I have several input checkboxes, (they name is same for send array on server).
So, I need get each value this checkboxes and I want use as selector checkbox names, this not works, help please.
<form> <input type="checkbox" name="bla[]" value="1" /> <input type="checkbox" name="bla[]" value="2" /> </form>
js:
$(document).ready( function () { $("input[name=bla]").each( function () { alert( $(this).val() ); }); });
DEMO
To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);
You are selecting inputs with name attribute of "bla"
, but your inputs have "bla[]"
name attribute.
$("input[name='bla[]']").each(function (index, obj) { // loop all checked items });
http://jsfiddle.net/26axX/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With