I'd like to populate an input with the comma seperated values of selected checkboxes and exclude duplicates.
The code below works but I don't know how to get the duplicates out.
HTML
<form>
<input type="text" value="" id="tags">
<input type="checkbox" value="apple"><label>apple</label>
<input type="checkbox" value="banana"><label>banana</label>
<input type="checkbox" value="melon"><label>melon</label>
<input type="checkbox" value="melon"><label>melon</label>
</form>
jQuery
$('input[type=checkbox]').change(function() {
var vals = $('input[type=checkbox]:checked').map(function() {
return $(this).val();
}).get().join(',');
$('#tags').val(vals);
});