Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  48] [ 5]  / answers: 1 / hits: 33009  / 13 Years ago, sun, may 22, 2011, 12:00:00

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.


More From » javascript

 Answers
45

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();>

[#92116] Friday, May 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
tobyl questions
Tue, Aug 10, 21, 00:00, 3 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
;