How to remove a disabled attribute using jQuery (IE)

I am in a situation where I need to use a disabled attribute to deactivate all inputs that I do not want to edit.

<input disabled="<%= disableInputs%>" type="text"></input> 

which displays

 <input disabled="False" type="text"></input> 

or

 <input disabled="True" type="text"></input> 

This works fine on Chrome and FF, but in IE it is not.

Now I am trying to remove these attributes (where disabled = "False") using javascript, but I am not getting the expected results. Againt, it runs javascript gor Chrome and FF, but not for IE (using 8).

at the end it should look like this:

 <input type="text"></input> 

or

 <input disabled="True" type="text"></input> 

my javascript looks like (I tried almost any combination):

 $('document').ready(function () { $("input[disabled='false']").each(function(){$(this).attr('disabled', false);}); $("select[disabled='false']").each(function(){$(this).attr('disabled', false);}); $("input[disabled='False']").each(function(){$(this).attr('disabled', false);}); $("select[disabled='False']").each(function(){$(this).attr('disabled', false);}); $("input[readonly='false']").each(function(){$(this).attr('readonly', false);}); $("select[readonly='false']").each(function(){$(this).attr('readonly', false);}); $("input[readonly='False']").each(function(){$(this).attr('readonly', false);}); $("select[readonly='False']").each(function(){$(this).attr('readonly', false);}); $("input[disabled='false']").each(function(){$(this).removeAttr('disabled');}); $("select[disabled='false']").each(function(){$(this).removeAttr('disabled');}); $("input[disabled='False']").each(function(){$(this).removeAttr('disabled');}); $("select[disabled='False']").each(function(){$(this).removeAttr('disabled');}); $("input[readonly='false']").each(function(){$(this).removeAttr('readonly');}); $("select[readonly='false']").each(function(){$(this).removeAttr('readonly');}); $("input[readonly='False']").each(function(){$(this).removeAttr('readonly');}); $("select[readonly='False']").each(function(){$(this).removeAttr('readonly');}); }); 

Live example: http://jsfiddle.net/2LNa6/ UPDATED

+1
jquery internet-explorer attributes
03 Oct '11 at 16:25
source share
4 answers

You should use the .prop method in jQuery, as it checks for you to work around these annoying IE errors. I see that you are using jQuery 1.6, so this should work:

 $('document').ready(function () { //get each input that is disabled $('input').each(function(i, el){ //see if it should be disabled (true|false) var disabled = $(el).data('disabled'); $(el).prop('disabled', disabled); }); }); 

Here is the updated jsFiddle .

+2
Jan 06 '13 at 14:06 on
source share
 $('document').ready(function () { $("input[disabled='False']").each(function(){$(this).removeAttr('disabled');}); $("input[disabled='false']").each(function(){$(this).removeAttr('disabled');}); }**)** 

You missed the closing shape (in bold)

Actual code must be

 $('document').ready(function () { $("input[disabled='disabled']").each(function(){$(this).removeAttr('disabled');}); }) 

And instead of False, go to disabled. This should work well in all browsers.

Use an attribute called a key to determine whether to include input or not. Here is the code. It will work in all browsers.

  <table class="tabla" cellpadding="0" border="0"> <tr> <td> <label>Names</label> </td> <td> <label>DoB</label> </td> <td style="width:82px" > <label>Gender</label> </td> </tr> <tr id="HijoCargoRow0"> <td> <input key="false" id="XXX" name="XXX" style="width:260px" type="text" value="" /> </td> <td> <input class="datepicker" key="true" id="YYY" name="YYY" style="width:70px" type="text" value="" /> </td> <td> <input key="true" id="M" name="ZZZ" type="radio" value="M" /><label for="M">M</label> <input key="true" id="F" name="ZZZ" type="radio" value="F" /><label for="F">F</label> </td> </tr> </table> <script> $(function(){ $("input[key='true']").each(function(){ $(this).attr('disabled','disabled') }); }); </script> 
0
Oct 03 '11 at 16:32
source share

You have a javascript error. Add); to the last line of your javascript and it will fix it.

0
Oct 03 2018-11-11T00:
source share

You can try a combination of the filter and prop selector in jQuery to remove the disabled attribute from all input tags:

 $("input").filter(function () { return $(this); }).prop("disabled'", false); 

http://api.jquery.com/filter/

0
Sep 20 '13 at 14:10
source share



All Articles