Change Image every 4 seconds in Javascript
Hello all,
The code below supposed to change the displayed picture from pic1 to pic2 in 4 seconds after pressing the 1st picture, when i execute it after 4 seconds there is an error saying "Pic is Undefined", please help me find the problem?
Thanx.
Code:
<head>
<script type="text/javascript">
function TimerSwitch(pic) {
TimerRunning=true;
var timer = setTimeout('SwitchPic(pic)', 4000);
}
function SwitchPic(pic) {
pic.src = "pic2.jpg";
}
</script>
</head>
<body>
<img class="switch" src="pic1.jpg" onclick="TimerSwitch(this)" />
</body>
</html>