Troy
Troy

Reputation: 399

Change all inputs with readonly attribute to disabled instead using jQuery

I'm having trouble with my jQuery syntax. Could someone show me how to iterate through all controls on a form that have the readonly attribute, remove the readonly attribute, and make then disabled instead? Thank you.

Upvotes: 1

Views: 4616

Answers (3)

Vanni Totaro
Vanni Totaro

Reputation: 5491

$('#your_form_id [readonly]').removeAttr("readonly").prop("disabled",true);

Upvotes: 0

iCreateAwesome
iCreateAwesome

Reputation: 4464

 $("#formID").each('input[readonly="readonly"]', function () {                
       $(this).removeAttr("readonly");
       $(this).attr("disabled", true);
 });

Not sure if you are doing this on page load, or on a link/button click, but this is a start.

Upvotes: 1

Blazemonger
Blazemonger

Reputation: 92983

$('input[readonly="readonly"]').removeAttr("readonly").prop("disabled",true);

Upvotes: 3

Related Questions