Forum Moderators: open
I'm trying to have have an image switch to another by clicking on it. And then when clicked again it will switch back.
Here's what i have so far:
<script language="javascript" type="text/javascript">
<!--
function switch(){
var id = document.getElementById("id").value;
var new_id = 1;
if(id == 1){
image_sm.src="image02.gif";
new_id = (id + 1);
}
if(id == 2) {
image_sm.src="image01.gif";
new_id = (id - 1);
}document.getElementById("id").value = new_id;
}
//-->
</script>
and the call to the script:
<p><a href="#" onclick="javascript:switch();"><img name="image_sm" src="image01.gif" border="0" alt=""></a></p>
<input type="hidden" id="id" value="1">
Switch must already be a function...
var someVar="foo"
switch(someVar){
case "foo":
case "bar":
alert("someVar = foo or bar");
break;
case "other":
alert("someVar = other");
break;
default:
alert("What?");
}