4
I have some checkbox and I want, when clicking a button, all the names of these selected, to go to an input separated by ",".
I tried to do it this way, but it didn’t 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 in Jsfiddle.
Where am I going wrong?
Possible duplicate of Update div with checkbox value marked
– William Aparecido Brandino
@Williamasimiliar may be possible duplicate, but, as you can see in my example, it’s not working. I even use the same resource that was presented in this link that sent.
– jsnow