tags:

views:

41

answers:

2

I am using this code to check the checkbox is chekced or not..

    $('#nextpage').click(function() {
       var result = $('#Details input[type=checkbox]').attr('checked');
        if (result == true) {
            $("#tabs").tabs('enable', 3).tabs('select', 3);
        }
        else {
            $().ShowDialog('please select atleast one');
        }
    });

using this I can check only for one checkbox if I need to check for multipe checkboxes in teh Details page how do I need to loop throw?

thanks

+2  A: 

I don't know exactly how you're using this in relation to the rest of your code, but this uses the each to check every checkbox:

$('#nextpage').click(function() {
    $('#Details input[type=checkbox]').each( function() {
        if( $(this).attr('checked') ) {
            $("#tabs").tabs('enable', 3).tabs('select', 3);
        } else {
            $().ShowDialog('please select atleast one');
        }
    });
});
Kerry
Here is the API Doc http://api.jquery.com/each/
orandov
If I use this I am not getting the pop up message when i dint selected anything?thanks
kumar
I don't know the ShowDialog function you're using, but you can try an alert. The each means it will alert it for EACH checkbox that is not selected.If you just want to check them all, you can try to add on a :checked to the end of the selector and count how many rows you get (if 0, then nothing is checked)
Kerry
+1  A: 

From what i understood from the discussion and code is that you want to switch tab only if one or more checkboxes are checked otherwise open a dialog box.

$('#nextpage').click(function() {
    var collection  = $('#Details input:checked');
   if(collection.length > 0 ) {
            //either loop on collection array or switch tab
            $("#tabs").tabs('enable', 3).tabs('select', 3);
   } else {
            $().ShowDialog('please select atleast one');
   }
});
Ayaz Alavi