kiran
kiran

Reputation: 1283

multiple set of check box?

im having a set of multiple check bxes, like one set contain 3 check box share same name another set contain 3 check sharing same name . how can i get the value of these two different set of check box using a single code .

    var form = $('usersurvey');
    checkboxes = form.getInputs('checkbox');
    for(count=0; count< checkboxes.length; count++){
        if(checkboxes[count].checked){
            retValue=true;
            break;
        }
    }
    return retValue;          
}

im tried with this code but it fetch all the check boxes , i want only that have the same name, i used prototype.js

Upvotes: 0

Views: 317

Answers (1)

trh178
trh178

Reputation: 11648

if you give each set of checkboxes a different class you could select them using jquery like:

$(".className").each(function(index, element) { ... }); 

for instance. somebody may be able to improve on this solution by selecting by name (i wasnt sure if you could do that, i always just select by class).

EDIT: sorry i should elaborate probably. the $(".className") piece will select all the checkboxes of class 'className'. since it sounds like you want to DO something with each of them though, i just added the each call on the end. inside the each call, you can define a function (shown) that will do something for each checkbox that was selected. reference the jquery each docs here:

http://api.jquery.com/each/

Upvotes: 1

Related Questions