Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

johnnyBravo

javascript whats wrong with my function or calling of it?

This topic is 5393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im using javascript...
heres some code that won't work
	function setNewSrc(txt) {
		document.txt.src="spainBear.gif";
	}
	function resetSrc(txt) {
		document.txt.src="teddy.gif";
	}


<img src="teddy.gif" name="teddy2" width="107" height="98" onMouseOver="setNewSrc('teddy2');" onMouseOut="resetSrc('teddy2');" />

its the parts that wont work. im trying to make a function where you type in the name and it works with the bottom code. thanks, [edited by - johnnyBravo on November 15, 2003 7:52:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
This is what youre trying to do:

function setNewSrc(name) {
eval("document."+name).src="spainBear.gif";
}

function resetSrc(name) {
eval("document."+name).src="spainBear.gif";
}

<img src="teddy.gif" name="teddy2" width="107" height="98" onMouseOver="setNewSrc(''teddy2'');" onMouseOut="resetSrc(''teddy2'');" />

However - I would do it like this:

function setNewSrc(img) {
img.src="spainBear.gif";
}

function resetSrc(img) {
img.src="spainBear.gif";
}

<img src="teddy.gif" width="107" height="98" onMouseOver="setNewSrc(this);" onMouseOut="resetSrc(this);" />


"Stop trying to hit me and hit me!"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!