Jump to content

Simple Javascript variables help


applenerd

Recommended Posts

Hey guys. I have a question about the animated buttons. The example that w3 uses is here:\HereThe code I am using is:<html><head><script type="text/javascript">function mouseOver(var i){document.i.src ="b_blue.gif"}function mouseOut(var i){document.i.src ="b_pink.gif"}</script></head><body><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver(b1)"onmouseout="mouseOut(b1)"><img border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b1" width="26" height="26" /></a><br /><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver(b2)"onmouseout="mouseOut(b2)"><img border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b2" width="26" height="26" /></a></body></html>If you can't see what I am doing I am trying to pass the name of the image to the function so that I do not need to copy the function. My problem is that it thinks my variable is the image. Does anyone know how to do what I am trying to do?thanks,applenerd

Link to comment
Share on other sites

while I see what you're doing, I've never had much luck with refering to the name like that. I usually just use getElementById and don't worry about how to do it the other way...<html><head><script type="text/javascript">function mouseOver(var i){document.getElementById(i).src ="b_blue.gif"}function mouseOut(var i){document.getElementById(i).src ="b_pink.gif"}</script></head><body><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver('b1')"onmouseout="mouseOut('b1')"><img border="0" alt="Visit W3Schools!" src="b_pink.gif" id="b1" width="26" height="26" /></a><br /><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver('b2')"onmouseout="mouseOut('b2')"><img border="0" alt="Visit W3Schools!" src="b_pink.gif" id="b2" width="26" height="26" /></a></body></html>

Link to comment
Share on other sites

Here.<html><head><script type="text/javascript">function mouseOver(i){if(i=='b1'){document.getElementsById("ref1").src ="b_blue.gif"}else{document.getelementsById("ref2").src="b_blue.gif"}function mouseOut(i){ if(i=='b1'){document.getElementById("ref1").src ="b_pink.gif"}else{document.getelementById("ref2").src="b_pink.gif"}}</script></head><body><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver('b1')"onmouseout="mouseOut('b1')"><img id="ref1" border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b1" width="26" height="26" /></a><br /><a href="http://www.w3schools.com" target="_blank"onmouseover="mouseOver('b2')"onmouseout="mouseOut('b2')"><img id="ref1" border="0" alt="Visit W3Schools!" src="b_pink.gif" name="b2" width="26" height="26" /></a></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...