November 24, 2001 - Disabling A Button
November 24, 2001 Disabling A Button Tips: November 2001
Yehuda Shiran, Ph.D.
|
Play around with the following two buttons. Toggle the second button with the first one:
Here is how the buttons are defined:
<BUTTON ID="b1" onclick="toggleOtherButton()">Toggle Other Button</BUTTON><BR><BR>
<BUTTON ID="b2" onclick="sayHello()" disabled>Say Hello</BUTTON><BR><BR><BR><BR>
The first button toggles the disability of the button below it, through the toggleOtherButton()
function:
function toggleOtherButton() {
if (b2.disabled) {b2.disabled = false;}
else b2.disabled = true;
}
Here is the whole JavaScript code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function toggleOtherButton() {
if (b2.disabled) {b2.disabled = false;}
else b2.disabled = true;
}
function sayHello() {
alert("Hello there");
}
// -->
</SCRIPT>