Reputation: 669
How to disable a html button on JavaScript onclick
event ? I am using a input type="button"
<input type="button" class="standardbutton" value="Password Reset" id="mybutton" onclick=" passwordReset()"/>
Since I am not using jquery or any framework for the UI, how to disable it?
I tried to set disabled = true
, but it didn't work.
For example:
document.getElementById("mybutton").disabled = true;
Upvotes: 1
Views: 694
Reputation: 19
<button id="button">My Button</button>
<p>Click the button below to disable the button above.</p>
<button onclick="disable()">Click</button>
<script>
function disable() {
document.getElementById("button").disabled = true;
}
</script>
Upvotes: 1
Reputation: 107
Set disabled = true in javascript function
<input type="button" class="standardbutton" value="Password Reset" id="mybutton" onclick=" passwordReset()"/>
In JS
function passwordReset(){
document.getElementById("mybutton").disabled = true;
}
Upvotes: 0
Reputation: 24915
Works fine for me
function disableBtn1(){
document.getElementById("btn1").disabled = true;
}
<input type="button" id="btn1" value="Btn 1"/>
<button id="btn2" onclick="disableBtn1();"> btn 2</button>
Upvotes: 5
Reputation: 4050
Set disabled=true
should work, you may have an error somewhere else :
function toggle_disable() {
var button = document.getElementById("test");
if (button.disabled) {
button.disabled = false;
} else {
button.disabled = true;
}
}
<input type="button" id="test" value="I'm a button"/>
<input type="button" id="toggle" onclick="toggle_disable()" value="<= Disable it !"/>
Upvotes: 2