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

  • Home
  • SEARCH
  • 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 8346673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:05:44+00:00 2026-06-09T07:05:44+00:00

I’d like to post an array of n length to a form. What’s the

  • 0

I’d like to post an array of n length to a form. What’s the best way to handle this?

The object is a Timesheet, which has a date, and an array of Lines.

Lines have a duration, category, and note field.

My form has a date field, and one line to start, and jQuery appends more lines as necessary.

I know I need to use bracket notation somehow, but I don’t know how considering I have two objects nested.

FWIW, the application end of things is in Node.js and express.

<form id="timesheet" method="POST" action="/timesheets">
  <label>date for timesheet</label>
  <input type="date" name="date"/><br/>
  <ol id="timesheet-list">
    <li>
      <input type="number" name="hours" min="0" value="0" step=".25"/>
      <input type="text" name="category"/>
      <input type="text" name="details"/>
    </li>
  </ol>
  <input type="submit"/>
</form>

<a id="addItem" href="#">Add a new line item</a>

<script type="text/javascript">
  $('#addItem').click(function(e){
    e.preventDefault();
    $('#timesheet-list').append('<li><input type="number"> <input type="text"> <input type="text"></li>');
  });
</script>
  • 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-09T07:05:45+00:00Added an answer on June 9, 2026 at 7:05 am

    I think you could serialize your input values if you want to submit it as a JSON data using the jQuery serializeArray method

          $('form').submit(function() {
              alert($(this).serializeArray());
              return false;
          });
    

    NOTE that for the above to work your <input ...> must have a name attribute.

    For others who may be looking to encode more complex data (object types) into form-data this answer here is helpful. Basically, it uses the serializeArray function to turn it into a JavaScript object (following code is included because the link may go inactive over time)

      $.fn.serializeObject = function()
      {
       var o = {};
       var a = this.serializeArray();
        $.each(a, function() {
           if (o[this.name] !== undefined) { //check to see if name attribute exists
               if (!o[this.name].push) { 
                  o[this.name] = [o[this.name]];
               }
               o[this.name].push(this.value || '');
             } else {
                o[this.name] = this.value || ''; 
              }
        });
        return o;
     };
    

    Using the function

     $(function() {
         $('form').submit(function() {
             $('#result').text(JSON.stringify($('form').serializeObject()));
          return false;
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.