Yesideez Posted November 26, 2007 Share Posted November 26, 2007 Hi, trying to get a rollover image using Javascript but can't get it to work. http://cheekymonkeys.pictureinthesky.net/equipment.php That's the direct link to the page and the six orange buttons should change to yellow but nothing is happening, not even an error in the status bar. Here's the code for the Javascript: <script language="JavaScript"> rollImage=new Array() rollImage[0]=new Image(141,23) rollImage[0].src="/gfx/btn_cloudsstars.gif" rollImage[1]=new Image(141,23) rollImage[1].src="/gfx/btn_cloudsstars_sel.gif" rollImage[2]=new Image(141,23) rollImage[2].src="/gfx/btn_pinkfairy.gif" rollImage[3]=new Image(141,23) rollImage[3].src="/gfx/btn_pinkfairy_sel.gif" rollImage[4]=new Image(141,23) rollImage[4].src="/gfx/btn_obstaclecourse.gif" rollImage[5]=new Image(141,23) rollImage[5].src="/gfx/btn_obstaclecourse_sel.gif" rollImage[6]=new Image(141,23) rollImage[6].src="/gfx/btn_bouncyslide.gif" rollImage[7]=new Image(141,23) rollImage[7].src="/gfx/btn_bouncyslide_sel.gif" rollImage[8]=new Image(141,23) rollImage[8].src="/gfx/btn_sumosuits.gif" rollImage[9]=new Image(141,23) rollImage[9].src="/gfx/btn_sumosuits_sel.gif" rollImage[10]=new Image(141,23) rollImage[10].src="/gfx/btn_availableextras.gif" rollImage[11]=new Image(141,23) rollImage[11].src="/gfx/btn_availableextras_sel.gif" function swapOut(imgName,imgID) { document.imgName.src=rollImage[imgID].src; alert "out"; return true; } function swapBack(imgName,imgID) { document.imgName.src=rollImage[imgID].src; alert "back"; return true; } </script> Here's a line of HTML for one of the buttons: <a href="equipment.php?item=clouds" onmouseover="swapOut('imgClouds',0)" onmouseout="swapBack('imgClouds',0)"> <img src="gfx/btn_cloudsstars.gif" name="imgClouds" alt="Clouds & Stars Castle" width="141" height="23" border="0" /> </a> I've split the HTML onto 3 lines to make it easier to read. I've also added an alert to help debug but I don't even get that. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 27, 2007 Author Share Posted November 27, 2007 Added "var" before declaring the "rollImage" variable. Changed the following code: document[imgName].src=rollImage[imgID].src; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.