Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of inputs with Jquery

Tags:

arrays

jquery

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());});
like image 584
A.Angelov Avatar asked Jan 26 '26 21:01

A.Angelov


1 Answers

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 ,.

like image 156
rahul Avatar answered Jan 29 '26 10:01

rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!