Entry
How can I disable a button after the first click?
Jun 21st, 2001 01:34
Martin Honnen,
The following code used the
disabled
property supported in NN6 and IE4+ and uses some self created
clicked
property for other browsers:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
button disabling
</title>
<script type="text/javascript">
function toggleButton (button) {
if (typeof button.disabled != "undefined")
button.disabled = !button.disabled;
else if (button.clicked) {
button.clicked = false;
button.value = button.oldValue;
}
else {
button.clicked = true;
button.oldValue = button.value;
button.value = 'DISABLED';
}
}
</script>
</head>
<body>
<form name="formName">
<input type="button" onclick="if (!this.clicked) {
alert('Kibology'); // example of click handler
toggleButton(this);
}"
name="aButton"
value="button"
/>
<input type="button" value="toggle button state"
onclick="toggleButton(this.form.aButton);"
/>
</form>
</body>
</html>