lalitpatadiya
lalitpatadiya

Reputation: 720

Remove readonly attribute from all input box using jquery?

I have multiple input text boxs all are by default read-only.

I want to Remove readonly attribute for all the input element within my form instead of particular element, i dont have any idea that with the jQuery how i can select all input and remove the readonly attributes if are added.

Html :

<input type="text" name="fistname" readonly="true">
<input type="text" name="lastname" readonly="true">
<input type="text" name="emailaddres" readonly="true">
<input type="text" name="password" readonly="true">
<input type="button" name="edit" id="edit">

Jquery :

$(document).ready(function(e){
    $(document).on("click","#edit",function(e){
         // What should i do here..?
    });
});

Upvotes: 0

Views: 8371

Answers (4)

user6116679
user6116679

Reputation:

$('#edit').click(function (){
   $('input[type=text]').removeAttr('readonly');
});

Upvotes: 0

Ibrahim Khan
Ibrahim Khan

Reputation: 20740

Use removeAttr() method like following.

$(document).on("click","#edit",function(e){
    $('input[type=text]').removeAttr('readonly');

    //$(':input').removeAttr('readonly'); //if want to select all types of form controls
});

Upvotes: 0

itzmukeshy7
itzmukeshy7

Reputation: 2677

$('input.canEdit').attr('readonly', false);

and add a class to all input elements you wants to allow user available to edit;

Upvotes: 0

Satpal
Satpal

Reputation: 133403

You should use prop() to set the properties

$(':input').prop('readonly', false)

OR, Use removeAttr() method

$(':input').removeAttr('readonly')

References

Upvotes: 7

Related Questions