• Advertisement

Archived

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

javascript whats wrong with my function or calling of it?

This topic is 5217 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
Even more than i asked for, thanks alot

ive been on this problem for a while!,

im not very good at javascript

thanks again!

Share this post


Link to post
Share on other sites

  • Advertisement