Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2006, 03:41 PM   PM User | #1
croniccoder
New to the CF scene

 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
croniccoder is an unknown quantity at this point
Correct syntax for document.write

Code:
document.write += ('<a href="'+ ads[adNumber].href +'" \n')
document.write += ('onMouseOver="status=\''+ ads[adNumber].mouseover +'\';return true" \n')
document.write += ('onMouseOut="status=\'\'"> \n')
document.write += ('<img src="' + ads[adNumber].src + '" width=' + ads[adNumber].width)
document.write += (' onLoad="setTimeout(\'newAd();\',' + refreshTime + ');"')
document.write += ('\n height=' + ads[adNumber].height + ' border=0 >')
document.write += ('</a>')

Can anyone possibly see a problem with the syntax of the above code?

The setTimeout function is never run so something is wrong with the syntax.
croniccoder is offline   Reply With Quote
Old 08-25-2006, 05:59 PM   PM User | #2
croniccoder
New to the CF scene

 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
croniccoder is an unknown quantity at this point
Code:
document.write += (' onLoad="setTimeout(\'newAd();\',' + refreshTime + ');"')
Actually it's just this line that isn't working. Any thoughts?

I've tried this 50 different ways already so it's not like I'm not trying to get this right.
croniccoder is offline   Reply With Quote
Old 08-25-2006, 06:06 PM   PM User | #3
Scriptbanger
New Coder

 
Join Date: Aug 2006
Location: Idaho
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Scriptbanger is an unknown quantity at this point
Try this:

Code:
document.write("<a href=\'"+ ads[adNumber].href +"\'\n");
Notice also the double quotes and single quotes have been reversed and the single quotes have been 'escaped' [that means that a \ has been put in front of each single quote so that the parser ignores it]. While some browsers/parsers can handle messy scripts others choke on it if everything isn't correct.

Also terminate the end of each line with a semicolon as in the example. Do this throughout your script and it should work fine. That is unless you have other errors.
__________________
.
+ Christ is the Rock - Rock On!
Scriptbanger is offline   Reply With Quote
Old 08-25-2006, 06:51 PM   PM User | #4
croniccoder
New to the CF scene

 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
croniccoder is an unknown quantity at this point
I tried that and it still doesn't work. I know its a incorrect syntax problem because in the original code:

Code:
document.write += ('<a href="'+ ads[adNumber].href +'" \n')
document.write += ('onMouseOver="status=\''+ ads[adNumber].mouseover +'\';return true" \n')
document.write += ('onMouseOut="status=\'\'"> \n')
document.write += ('<img src="' + ads[adNumber].src + '" width=' + ads[adNumber].width)
document.write += (' onLoad="setTimeout(\'newAd();\',' + refreshTime + ');"')
document.write += ('\n height=' + ads[adNumber].height + ' border=0 >')
document.write += ('</a>')
the images is being displayed, but the setTimeout function is never invoked.
croniccoder is offline   Reply With Quote
Old 08-25-2006, 07:24 PM   PM User | #5
zcorpan
New Coder

 
Join Date: May 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
zcorpan is an unknown quantity at this point
Get rid of +=.
zcorpan is offline   Reply With Quote
Old 08-25-2006, 08:48 PM   PM User | #6
Scriptbanger
New Coder

 
Join Date: Aug 2006
Location: Idaho
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Scriptbanger is an unknown quantity at this point
Gotta watch all the quotes/double quotes and escapes.

Try this:

Code:
document.write("onLoad=\'setTimeout(\"newAd()\"," + refreshTime + ");\n\'");
Also, what does the 'newAd()' function you are calling look like?
__________________
.
+ Christ is the Rock - Rock On!
Scriptbanger is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Advertisement
Log in to turn off these ads.