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="" />
Some read-only files can be changed to allow for edits by removing the read-only attribute in the file properties. Right-click the file and select Properties. Uncheck the box for Read-only and click OK.
click(function(){ // when the input is clicked, it looks to the previous input element // that has a `required` attribute, and sets its `readonly` property, // the `r` is the current readonly state (true or false) $(this). prev('input[required]').
Use setAttribute() Method to add the readonly attribute to the form input field using JavaScript. setAttribute() Method: This method adds the defined attribute to an element, and gives it the defined value. If the specified attribute already present, then the value is being set or changed.
You can do two things:
readonly
(case insensitive) attribute, using removeAttribute
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;
};
Well, to be simple! You can use jQuery to remove this attribute (jQuery would be simple, you can do this using JS too). Here is the code for that:
$('input[type=submit]').click(function () {
$('input[type=text]').removeAttr('readonly');
})
https://api.jquery.com/removeAttr/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With