Prop ("disabled", true); AND attr ('disabled', 'disabled') does not work in chrome and firefox

I have the following script inside my asp.net mvc view: -

function disableform(id) { $('#' + id).prop("disabled", true); } 

But the above function will only disable elements using Internet Explorer, but will not work on chrome or firefox, I also tried to write attr('disabled', 'disabled') instead of .prop("disabled", true); but this did not solve the problem.

my jQuery version is 1.7.1

So what could be the problem?

BR

+7
source share
4 answers

Form Disable wrong! IE just messed it up! you must disable the fields.

 function disableform(id) { $('#' + id+' :input').prop("disabled",true); }​ 

Demo

+8
source

I am running ASP.NET and had the same problem.

I dropped Jquery and went for pure Javascript and it did a great job.

  var element = document.getElementById('MyID'); element.setAttribute('disabled', 'disabled'); 

Edit: for proper operation you need to use element.removeAttribute ('disabled'); when you turn on the item. Otherwise, it remains disabled.

+1
source

I could not get it to work in chrome by deleting the property, so I just added a disabled class, it is not disabled, but it works on IE and Chrome

 $('#search').on('click', function (event) { $('#search').text("Searching"); $('#search').addClass("disabled"); return true; }); 
0
source
 function SwapA(SwapActivation) { for (i=1;i==5;i++) { if (i != SwapActivation) { // All Browsers supported ..... $("input[name=pg1"+i+"]").prop('disabled', true); $("input[name=pg2"+i+"]").prop('disabled', true); } else { // JQuery 1.10+ _&&_ Opera 12 and All other browsers... !!!! if ( $("input[name=pg1"+i+"]").prop('disabled') === true) $("input[name=pg1"+i+"]").prop('disabled', false); if ( $("input[name=pg2"+i+"]").prop('disabled') === true) $("input[name=pg2"+i+"]").prop('disabled', false); // works = JQuery 1.10+ _&&_ Opera 12.16 + Firefox 24; // do not work "Opera 17.0.1241.53", "Chrome" v.30.0.1599.101 m $("input[name=pg1"+i+"]").removeProp('disabled'); $("input[name=pg2"+i+"]").removeProp('disabled'); // .removeProp() is affects negative // works possible = JQuery 1.4.x : $("input").attr('name','pg1'+i)[0].removeProp('disabled'); $("input").attr('name','pg2'+i)[0].removeProp('disabled'); }}} 

useful? :)

-one
source

All Articles