2

how to send multiple fields with the same name via jQuery like this:

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

jQuery:

   function upload() {
    $.post('example.php', { text[]: Form.text[].value },
      function(output) {
      $('#result').html(output).show();
      });
    }

upload.php:

text[$i] = $_POST['text'][$i];

thank you,

EDIT: correct my question.

1 Answer 1

2

I believe that serialize() will do the right thing and produce the appropriate form parameters for such a set of inputs.

$(function() {
   $('form').submit( function() {
       $.post( 'foo.php', $('[name^=bar]').serialize(), function(data) {
           alert(data);
       });
       return false;
   });
});
Sign up to request clarification or add additional context in comments.

2 Comments

my question is how to send multiple fields with the same name via jQuery not to upload files!!
@Swell - I've updated my answer to address other types of inputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.