Reputation: 71
document.getElementById('confirm_save').onclick = function() {
this.disabled = true;
}
I have used the above code but still the button is not disabled
Upvotes: 1
Views: 65
Reputation: 67525
Your JS code is valid but you need to add type="button"
to your button so it will not act as a submit button and refresh the page returning to the initial status.
document.getElementById('confirm_save').onclick = function() {
this.disabled = true;
}
<button type="button" id="confirm_save">Confirm save</button>
Upvotes: 2
Reputation: 321
Maybe create a variable at the start associated with the button and disable it as such:
let btn = document.getElementById("confirm_save");
btn.addEventListener("click", function() {
btn.disabled = true;
});
Hope this helps;
Upvotes: 1
Reputation: 736
this should work:
document.getElementById('confirm_save').disabled = true;
Upvotes: 2