javascript whats wrong with my function or calling of it?

Started by
1 comment, last by johnnyBravo 20 years, 5 months ago
im using &#106avascript...

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]
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!"
Emil Johansen- SMMOG AI designerhttp://smmog.com
Even more than i asked for, thanks alot

ive been on this problem for a while!,

im not very good at &#106avascript <img src="smile.gif" width=15 height=15 align=middle><br><br>thanks again!

This topic is closed to new replies.

Advertisement