...

View Full Version : javascript link problem



neeep
04-25-2008, 06:18 PM
hi, I really need help with a javascript rollover piece of code. When you rollover the link button image, it creates an image change on the said link image, and on a transparent image elsewhere on the page. the link works fine on firefox and on safari, but the problem is that the link does not work at all on Internet Explorer. Basically it appears that the a href isnt being read by IE. I obviously need the link work on IE.

Here is an example of the code for one button

Head code...
function roll(cbutton, cover, mark, ya)
{
document[cbutton].src = cover;
document[mark].src = ya;
}
</script>


and the body code...



<A HREF="index.html"
onmouseover="roll('cbutton', 'cover.gif', 'mark', 'ya.gif')"
onmouseout="roll('cbutton', 'c.gif', 'mark', 'mark.gif')">

<div id="cbutton"><IMG SRC="c.gif" NAME="cbutton"></div>
</A>
<div id="mark"><IMG SRC="mark.gif" NAME="mark"></div>


the site is ciancorbett.com for the source code



I would really appreciate any help or ideas for how i can get the links to work in internet explorer.. Thank you.

abduraooft
04-25-2008, 06:21 PM
Basically it appears that the a href isnt being read by IE. I obviously need the link work on IE. Putting a div(block level element) inside <a>(inline element) is invalid.
Just validate your code by http://validator.w3.org and fix the errors

And I think,you could easily use CSS background property there, instead of that javascript based onmouseover, and ensure the effect for all your users.

shyam
04-25-2008, 06:51 PM
function roll(cbutton, cover, mark, ya)
{
document[cbutton].src = cover;
document[mark].src = ya;
}



<A HREF="index.html"
onmouseover="roll('cbutton', 'cover.gif', 'mark', 'ya.gif')"
onmouseout="roll('cbutton', 'c.gif', 'mark', 'mark.gif')">

<div id="cbutton"><IMG SRC="c.gif" NAME="cbutton"></div>
</A>
<div id="mark"><IMG SRC="mark.gif" NAME="mark"></div>


IE treats the id & name attribute interchangebly so when u say document[cbutton] it quite naturally thinks ur referring to the anchor link coz it comes first... you can fix it by using the following function


function roll(cbutton, cover, mark, ya)
{
document.images[cbutton].src = cover;
document.images[mark].src = ya;
}
which should work for both IE and mozilla a better solution would be to give unique ids to the images and use the document.getElementById method instead

btw, abduraooft has given some good advice to follow which will stand you in good stead in the longer run :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum