...

View Full Version : Please help!! what am I DOING WRONG!!



suicidalkatt
09-01-2007, 09:05 AM
Hi there... my first post and i'm asking for help :(

I'm working on a menu for a website I'm working on and I can't get the button mouseOver effect to work. Only the first button works. Any ideas as to what I might have done wrong?? I'm very new to Javascript and I'm SUPER noob!!

Ok here's my script:


<Script>
button1up = new Image; button1up.src = "images/home.gif";
button1down = new Image; button1down.src = "images/home_up.gif";
button2up = new Image; button2up.src = "images/products.gif";
button2down = new Image; button2down.src = "images/products_up.gif";
button3up = new Image; button3up.src = "images/promotions.gif";
button3down = new Image; button3down.src = "images/promotions_up.gif";
button4up = new Image; button4up.src = "images/contactus.gif";
button4down = new Image; button4down.src = "images/contactus_up.gif";
button5up = new Image; button5up.src = "images/warranty.gif";
button5down = new Image; button5down.src = "images/warranty_up.gif";

//MouseOver
function MouseOverRoutine(ButtonName)
{
if (ButtonName=="button1")
{document.button1.src = button1down.src;}
}
{
if (ButtonName=="button2")
{document.button2.src = button2down.src;}
}
{
if (ButtonName=="button3")
{document.button3.src = button3down.src;}
}
{
if (ButtonName=="button4")
{document.button4.src = button4down.src;}
}
{
if (ButtonName=="button5")
{document.button5.src = button5down.src;}
}
//MouseOut
function MouseOutRoutine(ButtonName)
{
if (ButtonName=="button1")
{document.button1.src = button1up.src;}
}
{
if (ButtonName=="button2")
{document.button2.src = button2up.src;}
}
{
if (ButtonName=="button3")
{document.button3.src = button3up.src;}
}
{
if (ButtonName=="button4")
{document.button4.src = button4up.src;}
}
{
if (ButtonName=="button5")
{document.button5.src = button5up.src;}
}

</script>


Here's my buttons:


<a href="main.html" onmouseOver="MouseOverRoutine('button1')" onmouseOut="MouseOutRoutine('button1')" target="content">
<Img Src="images/home.gif" name="button1" border="0" ></a>

<a href="products.html" onmouseOver="MouseOverRoutine('button2')" onmouseOut="MouseOutRoutine('button2')" target="content">
<Img Src="images/products.gif" name="button2" border="0" ></a>

<a href="promotions.html" onmouseOver="MouseOverRoutine('button3')" onmouseOut="MouseOutRoutine('button3')" target="content">
<Img Src="images/promotions.gif" name="button3" border="0" ></a>

<a href="contactus.html" onmouseOver="MouseOverRoutine('button4')" onmouseOut="MouseOutRoutine('button4')" target="content">
<Img Src="images/contactus.gif" name="button4" border="0" ></a>

<a href="warranty.html" onmouseOver="MouseOverRoutine('button5')" onmouseOut="MouseOutRoutine('button5')" target="content">
<Img Src="images/warranty.gif" name="button5" border="0" ></a>

Thank you so much for your help!!

_Aerospace_Eng_
09-01-2007, 09:19 AM
You have to many curly brackets. Make sure they match up.

suicidalkatt
09-01-2007, 09:21 AM
I changed it to this.. now all but the last button works


function MouseOverRoutine(ButtonName)
{
if (ButtonName=="button1")
{document.button1.src = button1down.src;}
if (ButtonName=="button2")
{document.button2.src = button2down.src;}
if (ButtonName=="button3")
{document.button3.src = button3down.src;}
if (ButtonName=="button4")
{document.button4.src = button4down.src;}
if (ButtonName=="button5")
{document.button5.src = button5down.src;}
}
function MouseOutRoutine(ButtonName)
{
if (ButtonName=="button1")
{document.button1.src = button1up.src;}
if (ButtonName=="button2")
{document.button2.src = button2up.src;}
if (ButtonName=="button3")
{document.button3.src = button3up.src;}
if (ButtonName=="button4")
{document.button4.src = button4up.src;}
if (ButtonName=="button5")
{document.button5.src = button5up.src;}
}

_Aerospace_Eng_
09-01-2007, 09:48 AM
Its actually new Image() not new Image, other than that it should work unless the path to the image is wrong.

suicidalkatt
09-01-2007, 10:13 AM
nvm my code is working fine now... weird...

http://bulbstar.com/test/test

Arty Effem
09-01-2007, 04:50 PM
nvm my code is working fine now... weird...

http://bulbstar.com/test/test
Today's expected standard is for buttons to be 'sticky' to indicate the current selection. This can be done with or without frames.

liorean
09-01-2007, 07:58 PM
Its actually new Image() not new Image, other than that it should work unless the path to the image is wrong.Actually, the parentheses are only needed if you want to send arguments to the constructor. Using new SomeConstructor; is entirely legal, and there is not a single browser hosted ECMAScript engine that fails to support it correctly.

You could argue it's bad style, however...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum