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
    Jan 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Syntax problems with breaking up html statement in javascript

    I can't seem to get an image to appear and I know it is because I can't break up this statement right the images are saved as ad1, ad2 etc. and it is supposed to come up with a random image managed to get it to work last night but then I left my memory stick and it is due today. Basically I can't get the quotation marks right.

    Code:
    document.write('<a href="rLink"><img source= "ad'+rNumber+'.js" alt="rAd"/></a>')
    Thanks.
    Last edited by kobyskid; 01-28-2009 at 02:37 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    document.write('<a href="rLink"><img src= ad" + rNumber + ".js" alt="rAd"/></a>')

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ya that didn't work

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by kobyskid View Post
    ya that didn't work
    well his code is correct, so maybe thats not the issue, can you post more of your script?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by kobyskid View Post
    ya that didn't work
    "How sharper than a serpent's tooth it is to have a thankless child! Away, away!" Shakespeare's 'King Lear', 1605

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    document.write('<a href="rLink"><img src= "ad'+rNumber+'.js" alt="rAd"/></a>')
    Should be src. That's the only error I can see. The reason Philips doesn't work is because it seems he didn't notice you're using single quotes and is using " to + the statements together. Your example was right in the first place. Just the source part needed changing.


  •  

    Posting Permissions

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