I have some checkboxes and I want you to click on a button, all the names of those selected, go to an input separated by ",".
I tried to do this, but it did not work:
<input type="checkbox" name="cbx-1">
<input type="checkbox" name="cbx-2">
<input type="checkbox" name="cbx-3">
<input type="text" id="text">
<button type="button" id="bt-ok">Ok</button>
<script type="text/javascript">
$('#bt-ok').click(function() {
$("input:checkbox[name=type]:checked").each(function(){
$("#text").val($(this).val());
});
});
</script>
Example on Jsfiddle .
Where am I going wrong?