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 3631950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:27:48+00:00 2026-05-19T00:27:48+00:00

I have an HTML Table that looks like this: The user can update any

  • 0

I have an HTML Table that looks like this:
alt text

The user can update any of the textboxes and select from the dropdowns.
Once he has completed his actions, The data needs to be sent via ajax to the server.
It is acceptable to send all values (Not only those that changed).

Need help building the JSON string for an ajax transaction.
(Note that the description column can be either a string, textbox or a dropdown in addition the dropdowns do not contain the same options.)

The structure I am trying to map to looks like this:

[
  {  id: "1" , desc: "Lenovo" , remark: "International" },
  {  id: "2" , desc: "Hard Disks", remark: ""           },
  {  id: "3" , desc: "T400", remark: "Old Model"        },
  {  id: "4" , desc: "Poker", remark: ""                }
]

Thanks a lot, if map can’t do it, I am open to other options.

Be happy and enjoy life 😉

Post acceptance note:
There is a hidden column between the feature and the description. This is why the indices in the answer are refereeing to cells[2] and cells[5].

  • 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-05-19T00:27:49+00:00Added an answer on May 19, 2026 at 12:27 am

    This should do it for you.

    It selects the rows, takes a .slice() of all but the first, then calls .map() to create your Array. The .get() actually pulls the Array out of the jQuery object.

    Inside .map(), I used DOM API properties and methods since it just seemed a little simpler (and faster) in this case.

    var ProductFeatures = $('#FeatureListTable tr').slice(1).map(function() {
        return {
            id: this.id,
            desc:this.cells[ 2 ].innerHTML,
            remark:this.cells[ 5 ].getElementsByTagName('input')[0].value
        }
    }).get();
    

    If you know there won’t be any whitespace inside the 6th cell (remark), you could change this line:

    remark:this.cells[ 5 ].getElementsByTagName('input')[0].value
    

    …to this:

    remark:this.cells[ 5 ].firstChild.value
    

    EDIT: As a side note, if you are able to change the HTML, I’d wrap the first row in a <thead> element, then the remaining rows in a <tbody> element to give separation to the different parts of the table.

    Then you could change this:

    $('#FeatureListTable tr').slice(1)
    

    …to this:

    $('#FeatureListTable > tbody > tr')
    

    …giving you the ability to select all except for the header row without the need for a separate .slice() call to remove the header from the set.

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

Sidebar

Related Questions

No related questions found

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.