Skip to main content

Enabling/Disabling Textbox using JavaScript

Below is the example for enabling or disabling of the text box whose id is "testTextbox".


HTML code of the text box

<p>
  <input type="text" id="testTextbox" ></input>
</p>

Javascript code for enabling the text box

document.getElementById("testTextbox").disabled = false;

Javascript code for disabling the text box

document.getElementById("testTextbox").disabled = true;


you can add the above javascript code in any of the javascript function you want and call it on some event or you can keep them disabled by keeping the input tags attribute to disabled like this they will always remain disabled and then you can enable them on some event

Comments