I have 100 inputs with the name table[]. How can I get their value with jQuery, as an array?
I am trying to do something like $_POST['table'] in PHP.
I tried the following code, but I want the values as an array...
$("input[name='table[]']").each(function(){document.write($(this).val());});
var arrInputValues = new Array();
$("input[name='table\\[\\]']").each(function(){
arrInputValues.push($(this).val());
// you can also use this
//arrInputValues.push(this.value);
});
Now your arrInputValues contains all the value.
You can also use
$("input[name='table[]']").each(function(){
You can see a working demo
You can use join() method to join the values in the array.
arrInputValues.join(',');
will join the array elements as a string separated by ,.
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