Get value of inputs with Jquery

They have: 1 posts

Joined: Mar 2010

I have 100 inputs with name - table[].
How to get their value with jQuery,like $_POST['table'] ,as I do in PHP.
I tryed

$("input[name='table[]']").each(function() {
document.write($(this).val());


});

but I want to get them as an array.

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Sorry to take ages to reply to this, also welcome to TWF! Smiling

You've already partially got the answer in your code there, if you run:

var tableInputs = $("input[name='table[]']");

Then you'll be able to use tableInputs as an array:

alert(tableInputs[0]);

You don't even have to use an intermediate variable, this works just as well:

$("input[name='table[]']")[0];

Although, if you're going to use the array in a for loop it would be better to put the result of $("input[name='table[]']") into a variable, then the $ function won't be called on every iteration of the loop.

a Padded Cell our articles site!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.