SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with onMouseOver

    I have the following script which loops for all alphabets and displays images. I wanted to display a different image onMouseOver but having problem with the syntax.

    <script language="javascript">
    var alphaArray= new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    var i=0;
    for (i=0; i<26; i++)
    {
    document.write('<img src="images/'+alphaArray[i]+'.gif" width=16 height=28 hspace=0 border=0 alt="'+alphaArray[i]+'" id="'+alphaArray[i]+'-horz" onMouseOver="document.images[\''+alphaArray[i]+'\'-horz].src='images/'+alphaArray[i]+'-over.gif'">');
    }
    </script>

    I am getting "Expected '('" error with this code
    onMouseOver="document.images[\''+alphaArray[i]+'\'-horz].src='images/'+alphaArray[i]+'-over.gif'"

    Please help.

    Thanks
    vmrao

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In onmouseover you are using single quotes to delimit the value of src, but you use single quotes around the entire document.write string. You need to use \' in that case.

    Also, instead of using document.getelement.... you can just use this.

    for example:
    onMouseOver="this.src=\'images/'+alphaArray[i]+'-over.gif\'"

    which means you can also lose the id attribute unless you need it for something else.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot. Worked like a Charm.


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
  •