Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:25:51+00:00 2026-06-13T09:25:51+00:00

I have a form in HTML which contains multiple same name fields. For example:

  • 0

I have a form in HTML which contains multiple same name fields. For example:

  <form action="" method="post" id="form">
    <div class="itemsection" id="item1">
      <input type="text" name="Price" />
      <input type="text" name="Name" />
      <input type="text" name="Catagory" />
    </div>
    <div class="itemsection" id="item2">
      <input type="text" name="Price" />
      <input type="text" name="Product" />
      <input type="text" name="Catagory" />
    </div>
    <div class="itemsection" id="item3">
      <input type="text" name="Price" />
      <input type="text" name="Product" />
      <input type="text" name="Catagory" />
    </div>
  </form>

Now on the server side (C#), I have an action method and a model class Product:

    //Action method accepts the form on server //It require the Product array 
    public ActionResult SaveItem(Product[] products)
    {
         .....
         ...
    }

    //Model class product
    public Class Product
    {
      public int Id { get; set; }
      public double Price { get; set; }
      public string Name { get; set; }
      public string Catagory { get; set; }
    }

Now my question is: I am submitting the form using jquery $.ajax method. On the server side the action method accepts a Product class array. Now how can I convert the form fields into a Json array (similar to product array). I tried:

   $("#form").serialize();  
           &
   $("#form").serializeArray();

The first generates the name-value pair of all the form fields and the second generates the name-value array of all the form fields. And my requirement is:

  //currently my form contains 3 item section so :
   [
    { "Price" : "value", "Name" : "value", "Catagory" : "value" }, 
    { "Price" : "value", "Name" : "value", "Catagory" : "value" }
    { "Price" : "value", "Name" : "value", "Catagory" : "value" }
   ]

Can anyone tell me how can I can achieve this through JavaScript or JQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:25:52+00:00Added an answer on June 13, 2026 at 9:25 am

    You can use the map method.

    var data = $('.itemsection').map(function(){
         return {
            Price: $('input[name="Price"]', this).val(),        
            Product: $('input[name="Product"]', this).val(),
            Category: $('input[name="Category"]', this).val()   
         }
    }).get();
    

    http://jsfiddle.net/KRJJ7/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just a basic html form within index.php which contains two text fields:
I have a HTML form that has certain fields which i am opening inside
I have a form in html (generated in php), which contains also a text
I have an html page which contains a div that displays the html from
I have a content submission form that contains multiple fields for input, all of
I have an HTML form which contains a drop down, a tinyMCE textarea, and
I have a partial view which contains the following snippet: @model Mbrrace.Domain.MbrraceForm <div class=row>
I have a an HTML form which contains the YAHOO rich text editor on
I have an html file which contains a form. There is lots of text
I have a jsp which contains a html form. Inside it there is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.