Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prop("disabled", true); AND attr('disabled', 'disabled') is not working in chrome and firefox

Tags:

jquery

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 the elements using internet explorer ,, but will fail to work on chrome or firefox, i also tried to write attr('disabled', 'disabled') instead of .prop("disabled", true);, but it did not solve the problem.

my Jquery version is 1.7.1

So what might be the problem?

BR

like image 295
john Gu Avatar asked May 02 '12 13:05

john Gu


Video Answer


2 Answers

Disabling a form is wrong! IE is just messing it out! you should disable fields.

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

DEMO

like image 129
ilyes kooli Avatar answered Oct 21 '22 06:10

ilyes kooli


I run ASP.NET and had this same issue.

I ditched Jquery and went to pure Javascript and it worked great.

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

Edit: For this to work properly you have to use element.removeAttribute('disabled'); when enabling the element. Otherwise it remains disabled.

like image 33
thinklarge Avatar answered Oct 21 '22 06:10

thinklarge