santa
santa

Reputation: 12512

Disable button with jQuery -- IE9 problem

I have a snippet of code that disables upload button until something is selected to be uploaded. I just noticed that it does not work in IE9 Beta. Do I need to iterate it somehow more for IE? Here's my code:

$("input:file").change(function(){
    if ($(this).val()) {
        $("input:submit").attr("disabled",false);
    }
});

UPDATE:

I modified my code to add an alert:

$("input:file").change(function(){
    alert("...");
    if ($(this).val()) {
        $("input:submit").removeAttr("disabled");
    }
});

In FF alert comes on and enables button, in IE alert is not triggered.

ONE MORE UPDATE:

The problem went ahead without code modification. In IE9 there's a new icon for "COMPATIBILITY VIEW" next to web address field. I clicked it to enable and then clicked again to disable and the issue went away. My guess, IE blocked jQuery somehow and cached it. By changing the compatibility settings I might've removed cached settings. WEIRD!

Upvotes: 1

Views: 6626

Answers (4)

Leon Revill
Leon Revill

Reputation: 2010

Here is a detailed tutorial from my website showing how to do this: jQuery disable button. In a nutshell the best way to disable a button using jQuery is using the following code:

$('.buttonElement').attr('disabled', 'disabled'); //TO DISABLED
$('.buttonElement').removeAttr('disabled'); //TO ENABLE

Hope this helps someone out.

Upvotes: 0

Phil Helix
Phil Helix

Reputation: 3723

This is the code I use to disable or re-enable a control:

function handleControlDisplay(className, foundCount, checked) {



    var button = jQuery(className);



    if (foundCount > 0 && foundCount == checked) {

        // enable

        button.removeAttr("disabled");

    }

    else {

        // set the disabled attribute

        button.attr("disabled", "true");

    };

}

Upvotes: 0

RoToRa
RoToRa

Reputation: 38400

There are browsers out there - obviously also IE9 - that don't allow you to access the value of a file input filed for security reasons.

Upvotes: 0

Kris Ivanov
Kris Ivanov

Reputation: 10598

try using $("input:submit").attr("disabled","disabled"); to disable and $("input:submit").removeAttr("disabled")

Upvotes: 3

Related Questions