Archived

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

johnnyBravo

javascript whats wrong with my function or calling of it?

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
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