views:

52

answers:

2
$(document).ready(
function()
{   
    $('input[id^="btnRemoveCategory"]').bind(
        'click',
        function(){
            if($('input[id^="chkIsBottom_":checked]'))
                alert('YES YES YES!!!!');
            else
                alert('No NO no!!!!!');

I've tried with the:

if($('input[id^="chkIsBottom_"]').attr(checked))

also....

where is my mistake???

10x

+2  A: 

You were very close with your first implementation.

Try this adjustment:

$(document).ready(
function()
{   
    $('input[id^="btnRemoveCategory"]').bind(
        'click',
        function(){
            if($('input[id^="chkIsBottom_"]:checked').length > 0)
                alert('YES YES YES!!!!');
            else
                alert('No NO no!!!!!');

Another option:

if($('input[id^="chkIsBottom_"]').is(':checked'))
Nate Pinchot
10x, i went with the other one, but 10x :-)
Erez
+3  A: 
$('input[id^="chkIsBottom_":checked]')

… is always going to return a true value. If none are checked, then it will be a jQuery object with no element inside it. You want:

$('input[id^="chkIsBottom_":checked]').length

(which will be false if the length is 0, and true if it isn't)

Meanwhile:

if($('input[id^="chkIsBottom_"]').attr(checked))

… will get the value of the X attribute of the first input element with an id that starts with chkIsBottom_, where X is whatever the variable checked contains (which is probably undefined, since you probably intended to pass a string).

David Dorward
10x, this did the job perfectly and then for the explenation :-)i will axcept it in 5 minutes, i can't right now....
Erez