John John
John John

Reputation: 1

prop("disabled", true); AND attr('disabled', 'disabled') is not working 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 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

Upvotes: 9

Views: 56845

Answers (4)

Sebastian Castaldi
Sebastian Castaldi

Reputation: 9004

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

$('#search').on('click', function (event) {
    $('#search').text("Searching");
    $('#search').addClass("disabled");
    return true;
});

Upvotes: 0

Roman Bondar
Roman Bondar

Reputation: 13

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

is useful? :)

Upvotes: -1

thinklarge
thinklarge

Reputation: 682

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.

Upvotes: 1

ilyes kooli
ilyes kooli

Reputation: 12043

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

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

DEMO

Upvotes: 11

Related Questions