Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery:IE only, input:checked returns 0 even when items selected

I'm seeing an error I can't replicate from a small subset of users. Here's the code:

var selected = $('#mytable input:checked');
if (selected.length == 0) {
    $('body').trigger('notice', 'Please select some items first');
    return;
}

Even when the user checks several checkboxes, the "notice" triggers. It seems selected.length is zero when it shouldn't be.


[UPDATE] The selector works when it's updated to:

var selected = $('input[class="selection"]:checked');

It seems including the id in the selector breaks things, only on IE.


This code is working for the vast majority of users and we can't replicate the issue, but for users that see the issue it's consistent and happens every time.

It seems to be isolated to IE (although I can't be sure). We're using jQuery 1.3.2 (from google CDN).

Any ideas?

like image 557
Parand Avatar asked Feb 01 '10 21:02

Parand


2 Answers

It would be a good idea to paste your surrounding code/event handler(s). For a starting point, I would suggest using the :checkbox selector in your first line:

$('#mytable input:checkbox:checked')

The manual says:

$(':checkbox') is equivalent to $('*:checkbox'), so $('input:checkbox') should be used instead.

Of course, that might not make any difference whatsoever. :checkbox is equivalent to $('[type=checkbox]'), so it might be that IE is choking on the input:checked part of your selector which is testing all input elements for the checked state.

like image 74
karim79 Avatar answered Nov 10 '22 12:11

karim79


I ran into a similar problem where, for the life of me, I could not get IE to recognize a box that had been 'checked' programmatically by another event handler.

resorted to:

$("input[name='iptName'][CHECKED]").size()

Apparently, IE (of the 8 flavored variety) was being sensitive about the case. ':checked', ':CHECKED', and '[checked]' were no-go.

Anyone else run into this?

like image 1
S. Rooks Avatar answered Nov 10 '22 11:11

S. Rooks