views:

52

answers:

1

This code does not disable my element as expected

if(Multifile.n==0){
    $("#btnUpload").attr("disabled","disabled");
}

This code does not enable my element as expected

$("#btnUpload").attr("disabled","");

I added these lines in jQuery.MultiFile.js after what I believe is the location where files are added and removed from the MultiFile object. As far as I can tell, MultiFile.n is a counter.

How can I disable btnUpload when there are no files in the list, and enable it as long as there is at least one.

A: 

If there is a disabled attribute on the element, it will always be disabled, even if the attribute is empty. This is because the original (SGML variant of) HTML had attributes without values like this

<INPUT TYPE="text" DISABLED>

So you have to remove the attribute

$('#btnUpload').removeAttr('disabled');
Jan Willem B
I removed the initial attribute, and it still never changes
David
then probably the button involved is not the element with the btnUpload id. Have you checked that with the google chrome element inspector? (right click -> inspect element)
Jan Willem B
it is definitely the element with id (and name attribute) equal to btnUpload. should I check something other than page source?
David
i used firebug `<input type="submit" id="btnUpload" value="Upload All" name="btnUpload">`
David
I'm afraid I am out of ideas
Jan Willem B
i mentioned above that i discovered the count was actually at 2 when there were no files in the list. i've also confirmed that the location of my toggle code is good. however, i can't get the button to initialize disabled unless i set the `<input disabled>` in which case it remains disabled forever.
David
i think there was an additional syntax error. thanks
David