var checked_boxes = "";
for(var i=0; i<total_checkboxes; i++) {
var cur_box = document.getElementById('userbox_' + i);
if(cur_box.checked) {
checked_boxes += i + '|||';
}
}
var all_checkboxes = document.getElementById('all_checkboxes');
all_checkboxes.value = checked_boxes;
now this is assuming all of your userid's are 0,1,2,3,... and the checkbox names are setup with the name/id as 'userbox_0', 'userbox_1', 'userbox_2',... i'm also guessing that you're user id's won't be consecutive like that. you might try populating an array (user_ids for example), then giving that to the javascript via a template variable. once that array is stored in js, you could just use user_ids.length for the total_checkboxes and just use user_ids[i] to reference the user id stored in the array.
you might also want to look at the JSON perl module as well for transferring data to and from javascript applications. this might be confusing at the time if you're just using javascript, but you can find more information at json.org |