Place a single button on a page that could be used as an ON/OFF switch. Design this button so that the button is labeled "ON". When you click on the button its label should change to "OFF". Clicking on it again should change it back to "ON" and so on.
Asked
Active
Viewed 3.4k times
1 Answers
8
This ok?:
<script type="text/javascript">
function onoff(){
currentvalue = document.getElementById('onoff').value;
if(currentvalue == "Off"){
document.getElementById("onoff").value="On";
}else{
document.getElementById("onoff").value="Off";
}
}
</script>
<input type="button" value="On" id="onoff" onclick="onoff();">

fl00r
- 82,987
- 33
- 217
- 237