I have a lot of input
s with the same name
attribute. I know how to get them all as jQuery object!
The console.log()
prints-out something like this:
[
<input type="checkbox" name="people" value="33" checked="checked">
,
<input type="checkbox" name="people" value="1" checked="checked">
]
After that, I need to send an AJAX request to server that contains all IDs of people (value
attribute).
Obviously, I can chain serialize()
to that jQuery object and the result will be like:
people=33&people=1
...but I'm looking for 'more-friendly' way. 'More-friendly' to PHP, so I can do like:
foreach ($_POST['people'] as $people) {
echo $people;
}
PHP requires multiple checkboxes of the same name to use bracket notation. Using the following naming convention should allow you to do what you want.
<input type="checkbox" name="people[]" value="1" checked="checked">
.serializeArray() might do the trick: http://api.jquery.com/serializeArray/
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