Alex Rivera | Logout

How to get an Array with jQuery, multiple <input> with the same name

Asked 2010-04-13T07:48:02.217
65

I have a form where users can add input fields with jQuery.

<input type="text" id="task" name="task[]" />

After submitting the form I get an array in PHP.

I want to handle this with the $.ajax() but I have no idea how to turn my <input>s to an array in jQuery.

Edit
Report

1 Answer

35

For multiple elements, you should give it a class rather than id eg:

<input type="text" class="task" name="task[]" />

Now you can get those using jquery something like this:

$('.task').each(function(){
   alert($(this).val());
});
answered 2010-04-13T07:51:56.067

Your Answer