0

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..?
    });
});
3
  • $('input').removeAttr('readonly') api.jquery.com/removeAttr Commented Mar 29, 2016 at 6:20
  • 2
    Possible duplicate stackoverflow.com/questions/2496443/… Commented Mar 29, 2016 at 6:23
  • 1
    @JohnR , i guess removing readonly attribute for an individual input element and within an entire form is a different thing with selecting all the inputs using jQuery! He might not have an idea that how to select all the inputs of a form using jQuery Commented Mar 29, 2016 at 7:02

4 Answers 4

7

You should use prop() to set the properties

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

OR, Use removeAttr() method

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

References

Sign up to request clarification or add additional context in comments.

Comments

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

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

Comments

0

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
});

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.