Submit multiple input fields which have the same 'name' attribute Submit multiple input fields which have the same 'name' attribute mongoose mongoose

Submit multiple input fields which have the same 'name' attribute


You should make a json object for each of your record and send an array of your objects to the backend.. And access it as you want in node.js

Or if its an array with single dimension, you can generate an array directly as

Something like

var myPrices = [];function createArray() {    $("input[name=price]").each(function() {        var price = $(this).val();        myPrices.push(price);    });    console.log(myPrices);    return myPrices}

And yes, It is a bad practice to use the same name and id for multiple input fields.

A better approach will be that,

You will have a pair of in one row. Keep one button to add such rows dynamically.

In the end, when the user is done, make a json object of each row as

{    name: 'FRUITNAME',    price : 'PRICEOFFRUIT'}

create an array of such objects and then send it to server side.