How to Disable and Enable HTML Inputs, Buttons or Textareas
HTML inputs, buttons and textareas have the "disanled" attributes. if you want to set them to be disabled, you can put the "disabled" attribute in the html tags such as
<button disabled>button</button> <input disabled> <textarea disabled>></textarea>
What if we want to disable the above elements?
We can use the following code.
<button id = "demobutton">button</button>
<button onclick="demobutton.disabled = false">enable button</button>
<script>
demobutton.disabled = true;
</script>
Interesting Facts
- You can use somebutton.setAttribute("disabled","true"), but you can't use somebutton.setAttribute("disabled","false"), because the 'disabled' attribute is not defined by disabeld = "true" or "false".
- If the "disabled" attribute is there, it will be disabled, regardless the value to be true or false.
Comments
Post a Comment