SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    cork
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking simple script syntax error

    Hi all,

    Here is my code below:


    function GetAlbum()

    {
    var albumname = GetCookie(cookiename3);

    if(albumname)
    document.write("<a href='repositorypfs"+albumname+".html' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage('Image4',' ','images/platb.gif',1)'><img src='images/plata.gif' name='Image4' width='98' height='26' border='0'></a>");
    else
    document.write("[not set]");
    }


    I had to switch the usual double quotes for single quotes, otherwise the script would close itself. However it is obviously wrong.

    As it is the image is displayed, the cookie contents are inputted and the link works but the rollover does not work.

    Any ideas??

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44° 56.537' W 123° 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still have double quotes in there that need replacing. The only ones should be at the very beginning and the very end of your document.write, just after the opening parenthesis and just before the closing.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The rollover doesn't work because you've got single quotes delimiting both the function call and the some of the function arguments. Single quotes are typically used to delimit JS strings that print HTML, as HTML prefers doubles. Just escape any nested singles:
    Code:
    if(albumname)
    document.write('<a href="repositorypfs' + albumname + '.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image4\',\' \',\'images/platb.gif\',1)"><img src="images/plata.gif" name="Image4" width="98" height="26" border="0"></a>');
    else
    document.write('[not set]');
    }
    ::: certified wild guess :::

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    cork
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hey

    thanks, that worked a treat. I knew that the qoutes were delimiting the function but wasn't sure about the exact way around it.

    Thanks again.

    Slán


Bookmarks

Posting Permissions

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