I am trying to make a simple toggle button in javascript.
Posted
by CDeanMartin
on Stack Overflow
See other posts from Stack Overflow
or by CDeanMartin
Published on 2010-06-15T18:03:10Z
Indexed on
2010/06/15
18:12 UTC
Read the original article
Hit count: 154
JavaScript
I am trying to make a simple toggle button in javascript. However, the button will only turn "OFF" and will not turn back "ON"
<html><head></head>
<script type="text/javascript">
function toggle(button)
{
if(document.getElementById("1").value=="OFF"){
document.getElementById("1").value="ON";}
if(document.getElementById("1").value=="ON"){
document.getElementById("1").value="OFF";}
}
</script>
<body>
<form action="">
<input type="button" id="1" value="ON" style="color:blue"
onclick="toggle(this);">
</form></body></html>
I am running:HP Netbook : Ubuntu Linux 10.04 : Firefox for Ubuntu 1.0.
© Stack Overflow or respective owner