-2

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...

Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Arjun D Nair
  • 217
  • 1
  • 3
  • 14
  • 1
    give 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
  • 3
    Possible 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 Answers2

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;
}