Using functions to swap images
Ok, so this is my problem. I want multiple images to be able to call this function and run it as planned. This is my question, how do you make it so that the name of the tag can be dynamic in the function. Sorry if I don't make myself clear, here's my code if it helps.
<html>
<head>
<title>Example</title>
</head>
<script type="text/javascript">
function one( a, b ){
if ( a == 1 ){
/* right here were it says document.one.src = one.jpg;
how do I make it so that "one", the name of the <img>, can be dynamic so that other <img> can put the name of their tags there? */
document.one.src = b;
}
else if ( a == 2 ){
document.one.src = b;
}
}
</script>
<body>
<a onMouseOver="one( 1, 'one.jpg' )" onMouseOut="one( 2, 'two.jpg' )">
<img name="one" src="two.jpg" />
</a>
<!-- I want it so that this image can call the same function and replace "one" in "document.one.src" with its name; "two" -->
<a onMouseOver="one( 1, 'one.jpg' )" onMouseOut="one( 2, 'two.jpg' )">
<img name="two" src="two.jpg" />
</a>
</body>
</html>
Ok, so this isn't EXACTLY my code, but it's exactly the same thing as what I'm doing. I just gave some parts easier names, so it's easier to follow. Oh, and if I forgot to say, this is an image swap. So can someone please help me?
|