views:

175

answers:

2

I have 5 check box lists, which all are selectives, which are criterias which need to be chosen in order to create filters.

What I need is to have something like this, after selecting items from the check box lists, just for the user to have an idea what he or she has chosen

"You have chosen countries - United Kingdom, Africa" "You have chosen languages - English, Italian, Spanish"

+1  A: 

I would normally use jquery to handle this efficiently. Using Jquery you could reference the value of one group with a class of group1 (for a single tick) using...

$(".group1:checked").val();

or for multiple ticks with a class of .mycheckboxes

var result = "";
$(".mycheckboxes").each( function () {
    result = result + $(this).val() + ", ";
});

alert(result);

More info plus Source of above code here: http://jquery.open2space.com/node/15

I <3 Jquery ;)

Julian Young
JQuery will be fine :-)Basically what I have, is about 5 checkbox lists, with criterias such as languages, countries and so on. And when the user is finished ticking from a checkboxlist, a <DIV> in the page, is filled with text such as"You have chosen English, Spanish for langauges"Could you post a code snippet on how to accomplish this? I am already using JQuery on the page, so it should not be a problem :)Thanks for your help!
A: 
var checkboxes = document.forms.myform.elements.mycheckboxgroup;
var checked_values = "";
for (var i = 0, j = checkboxes.length; i < j; i++) {
    var checkbox = checkboxes[i];
    if (checkbox.checked) {
        if (checked_values.length > 0) {
            checked_values += ", ";
        }
        checked_values += checkbox.value;
    }
}
David Dorward