SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Problem with onMouseOver
-
Oct 6, 2006, 10:26 #1
- 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
-
Oct 6, 2006, 11:36 #2
- 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.
-
Oct 6, 2006, 12:10 #3
- Join Date
- Mar 2004
- Location
- Farmington
- Posts
- 80
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks a lot. Worked like a Charm.
Bookmarks