Disable readonly to text box onclicking the button

html, javascript

Solution

You can do two things:

- Remove the `readonly` (case insensitive) attribute, using `removeAttribute`

- Set the `readOnly` (case sensitive) property to `false`

HTML:

<input id="myInput"  type="text"  readonly="readonly" /><br />
<input id="myButton" type="submit" value="update" />

JS (option 1): [Demo]

document.getElementById('myButton').onclick = function() {
    document.getElementById('myInput').removeAttribute('readonly');
};

JS (option 2): [Demo]

document.getElementById('myButton').onclick = function() {
    document.getElementById('myInput').readOnly = false;
};

Problem

I have used "readonly" attribute to the textbox which makes the textbox non editable and may i know how to disable the readonly attribute on clicking the button. can we do this by using any script ? ``` <input type="text" name="" value="" readonly="readonly"/><br/> <input type="submit" name="" value="update" onclick="" /> ```

Original source