Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Aug 2006
    Location
    Idaho
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Get rid of +=.

  • #6
    New Coder
    Join Date
    Aug 2006
    Location
    Idaho
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •