I have a set of checkboxes which all have the same name called 'Department'. Whenever a user checks one or more of these Department
checkboxes I want the values to be seralized and sent via AJAX so that it can retrieve more data based on the selected values.
So far I have done this:
$('#user-Departments input[name="Department"]').change(function () {
var selected = $('#user-Departments input[name="Department"]').serialize();
console.log(selected);
});
So if any of the Department
checkboxes change in the div with id of user-Departments
, then I'm asking JQuery to seralize the values. The value is contained in the ID attribute of each checkbox. But my console is showing this:
Department=4&Department=9
How do I get just the values 4 and 9 into a comma-delimited string e.g. "4,9" so that I can pass it as a list to my web server (Coldfusion)?
ADDED JSFIDDLE: http://jsfiddle.net/mjcJ4/