Skip to content
Advertisement

Send multiple elements with jQuery POST

I have this jQuery code to add<select> elements in a table row with an “add” button:

JavaScript

What do I need to modify in the below code to be able to POST multiple values from the select elements as an array? Right now it only inserts one value at the time to my MySQL database.

JavaScript

Advertisement

Answer

First of all you have to use classes for your selects instead of an id. jQuery will only return one element when you use an id. After that the following function will convert all values of the selects you give as paramater as an array.

JavaScript

So:

JavaScript

Should for example return:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement