I'm using a button tag to create the button. I want to disable the button when I click on it. But I'm not able to do it. I hope someone here can help me...
Asked
Active
Viewed 1,033 times
-2
-
1give some code what you have tried! – Zico Nov 15 '18 at 05:45
-
also, why do not you try with input tag giving type = 'Button' – Jayanth Nov 15 '18 at 05:47
-
3Possible duplicate of [Disable submit button ONLY after submit](https://stackoverflow.com/questions/17106885/disable-submit-button-only-after-submit) – Ori Marko Nov 15 '18 at 06:39
-
Hi and welcome to Stack Overflow :). Can you be more specific about your problem, please? If possible, please add your HTML and your JavaScript, if you have tried some, but at least your HTML. Thanks! – CodeF0x Nov 15 '18 at 08:52
2 Answers
0
You need to change the .disabled
property of the button.
var btn = document.querySelector("#submit-btn");
btn.disabled = true;
Live example:
var btn = document.querySelector("#submit-btn");
btn.addEventListener('click', function() {
submit();
});
function submit() {
btn.disabled = true;
}
#submit-btn {
width: 100%;
height: 30px;
border: solid black .5px;
}
#submit-btn:disabled {
background-color: gray;
}
<input type="submit" id="submit-btn" value="Submit">
Resourced from this question.

Maytha8
- 846
- 1
- 8
- 26
0
HTML <input type="button" id="btn1" onClick="clicked()" value="text">
JS
function clicked(){
var btn1 = document.getElementById("btn1");
btn1.disabled = true;
}

Alesandro Giordano
- 373
- 1
- 13