I intend to include a button in my traffic light code so that the user can click on it to activate the traffic light however, i am unsure of where to place it in my code.
Place the button wherever you like inside the body tag.
<input type="button" name="start" value="Start/stop Traffic light" onclick="startStop()">
Remove the setTimeout
and the slideit()
initial call.
var step=1;
function slideit()
{
document.images.slide.src = eval("image"+step+".src");
if(step<4)
step++;
else
step=1;
}
And add the startStop
function below and the working
variable declaration.
var working;
function startStop() {
if (typeof working != 'undefined') working = clearInterval(working);
else working=setInterval("slideit()", 3000);
}