Submitting multiple inputs with same name

r34

Ok, so I have form for creating polls. I want to use AJAX request and able user to attach image instead of question, so I use FormData for this.

I could't find any solution for working with multiple input with same name (named like this: "name[]"). I tried this option:

var fdata = new FormData();
fdata.append('answers[]', $('input[name="answer[]"]').val());

But it doesn't work. I know I could use .each(), but I don't want different name for each question, so I don't have to rebuild PHP side too much.

Thanks for any help.

Quentin

You have to append each value in turn. Currently you are only appending the first one (because that is what val() returns.

$('input[name="answer[]"]').each(function (index, member) {
    var value = $(member).val();
    fdata.append('answers[]', value);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple inputs with same name

From Dev

Django - Submitting form with multiple inputs for same field

From Dev

Add multiple inputs with same name to mysql database

From Dev

Two inputs with the same name

From Dev

how to get value of Multiple text inputs with same name

From Dev

Yii2 validation rule for multiple inputs with same name

From Dev

Request data from form with multiple inputs using the same name

From Dev

javascript synchronize inputs with same name

From Dev

Multiple form inputs for the same field

From Dev

validating multiple inputs at the same time

From Dev

How does MVC decide which value to bind when there are multiple inputs with the same name?

From Dev

Form with two inputs not submitting?

From Dev

How to put multiple Bootstrap inputs on same line?

From Dev

Same error check for multiple inputs with jQuery

From Dev

Multiple parameters by the same name

From Dev

Multiple functions with the same name

From Dev

Multiple divs with same name

From Dev

Codeigniter: How do I pass multiple inputs with multiple same names?

From Dev

Codeigniter: How do I pass multiple inputs with multiple same names?

From Dev

Submitting form after validating inputs

From Dev

Multiple forms in the same page, keep data populated when submitting

From Dev

Capybara how i can fill_in all inputs with the same name?

From Dev

target inputs with same name different forms on 1 page with php

From Dev

Capybara how i can fill_in all inputs with the same name?

From Dev

Count value of inputs with same name and copy final value to another input

From Dev

how do i save three inputs to a file with same name as the user?

From Dev

in codeigniter, i am using same name for multiple inputs(type="text"), during submit i want to allow at least one value, how can i validate?

From Dev

Multiple EJB beans with same name

From Dev

Multiple Inheritance: same variable name

Related Related

  1. 1

    Multiple inputs with same name

  2. 2

    Django - Submitting form with multiple inputs for same field

  3. 3

    Add multiple inputs with same name to mysql database

  4. 4

    Two inputs with the same name

  5. 5

    how to get value of Multiple text inputs with same name

  6. 6

    Yii2 validation rule for multiple inputs with same name

  7. 7

    Request data from form with multiple inputs using the same name

  8. 8

    javascript synchronize inputs with same name

  9. 9

    Multiple form inputs for the same field

  10. 10

    validating multiple inputs at the same time

  11. 11

    How does MVC decide which value to bind when there are multiple inputs with the same name?

  12. 12

    Form with two inputs not submitting?

  13. 13

    How to put multiple Bootstrap inputs on same line?

  14. 14

    Same error check for multiple inputs with jQuery

  15. 15

    Multiple parameters by the same name

  16. 16

    Multiple functions with the same name

  17. 17

    Multiple divs with same name

  18. 18

    Codeigniter: How do I pass multiple inputs with multiple same names?

  19. 19

    Codeigniter: How do I pass multiple inputs with multiple same names?

  20. 20

    Submitting form after validating inputs

  21. 21

    Multiple forms in the same page, keep data populated when submitting

  22. 22

    Capybara how i can fill_in all inputs with the same name?

  23. 23

    target inputs with same name different forms on 1 page with php

  24. 24

    Capybara how i can fill_in all inputs with the same name?

  25. 25

    Count value of inputs with same name and copy final value to another input

  26. 26

    how do i save three inputs to a file with same name as the user?

  27. 27

    in codeigniter, i am using same name for multiple inputs(type="text"), during submit i want to allow at least one value, how can i validate?

  28. 28

    Multiple EJB beans with same name

  29. 29

    Multiple Inheritance: same variable name

HotTag

Archive