Forum Moderators: open

Message Too Old, No Replies

Rollover for menu

         

toplisek

8:40 am on May 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would like to change button when user goes over link.
What to change that it will work?
[PHP]

<a href="index.php"
onmouseover="changeImages('website_01', 'images/home_over.jpg'); return true;"
onmouseout="changeImages('website_01', 'images/home.jpg'); return true;"
>
<img name="website_01" src="images/home.jpg" width="79" height="20"></a>

and Javscript:

function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}
}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
website_01_over = newImage("../images/home_over.jpg");
preloadFlag = true;
}
}

Need help.
Regards and thank you.

colandy

11:22 am on May 11, 2007 (gmt 0)

10+ Year Member



OK, I've changed you code slightly but this should give the desired effect, I have tested so should work.

<SCRIPT ........>
function changeimage(id, type)
{
var mdiv=document.getElementById(id);
if(type=='over')
{
setAttribute('src','images/test_over.gif');
}
else
{
setAttribute('src','images/test.gif');
}
}
</SCRIPT>

<a href="#"><img id="home" src="images/test.gif" onmouseover="changeimage('home','over');" onmouseout="changeimage('home','out');"></a>

Only one issue is that this will only work on one menu image if you want more then you'll have to check the content of id b4 you swap the image.