...

View Full Version : Correct syntax for document.write



croniccoder
08-25-2006, 04:41 PM
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
08-25-2006, 06:59 PM
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.

Scriptbanger
08-25-2006, 07:06 PM
Try this:



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. :D

croniccoder
08-25-2006, 07:51 PM
I tried that and it still doesn't work. I know its a incorrect syntax problem because in the original 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.

zcorpan
08-25-2006, 08:24 PM
Get rid of +=.

Scriptbanger
08-25-2006, 09:48 PM
Gotta watch all the quotes/double quotes and escapes.

Try this:



document.write("onLoad=\'setTimeout(\"newAd()\"," + refreshTime + ");\n\'");

Also, what does the 'newAd()' function you are calling look like?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum