Web Analytics Made Easy -
StatCounter Problem with onMouseOver - CodingForum

Announcement

Collapse
No announcement yet.

Problem with onMouseOver

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    You forgot to escape some single quotes eg: \' and also had a quote in the wrong place causing document.images['a'-horz] instead of ['a-horz'].

    I suggest using an editor with synax highlighting.

    my favorite is Notepad++
    Code:
    <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>

    Comment

    Working...
    X