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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:04:06+00:00 2026-06-01T14:04:06+00:00

I have a form that I am using AJAX to pass values with. The

  • 0

I have a form that I am using AJAX to pass values with. The form is somewhat dynamic depending on the new fields a user can add inside of the backend. I’ve ended up with something kind of hideous like this:

  var collected = {     
      1 : $('#wpsc_checkout_form_1').val(),          
      2 : $('#wpsc_checkout_form_2').val(),
      3 : $('#wpsc_checkout_form_3').val(),
      4 : $('#wpsc_checkout_form_4').val(),
      5 : $('#wpsc_checkout_form_5').val(),
      6 : $('#wpsc_checkout_form_6').val(),          
      7 : $('#wpsc_checkout_form_7').val(),          
      8 : $('#wpsc_checkout_form_8').val(),
      9 : $('#wpsc_checkout_form_9').val(),
      10 : $('#wpsc_checkout_form_10').val(),
      11 : $('#wpsc_checkout_form_11').val(),          
      12 : $('#wpsc_checkout_form_12').val(),
      13 : $('#wpsc_checkout_form_13').val(),
      14 : $('#wpsc_checkout_form_14').val(),
      15 : $('#wpsc_checkout_form_15').val(),
      16 : $('#wpsc_checkout_form_16').val(),          
      17 : $('#wpsc_checkout_form_17').val(),          
      18 : $('#wpsc_checkout_form_18').val(),
      19 : $('#wpsc_checkout_form_19').val(),
      20 : $('#wpsc_checkout_form_20').val(),          
      21 : $('#wpsc_checkout_form_21').val(),          
      22 : $('#wpsc_checkout_form_22').val(),
      23 : $('#wpsc_checkout_form_23').val(),
      24 : $('#wpsc_checkout_form_24').val(),
      25 : $('#wpsc_checkout_form_25').val(),
      26 : $('#wpsc_checkout_form_26').val(),          
      27 : $('#wpsc_checkout_form_27').val(),          
      28 : $('#wpsc_checkout_form_28').val(),
      29 : $('#wpsc_checkout_form_29').val(),
      30 : $('#wpsc_checkout_form_20').val(),          
      31 : $('#wpsc_checkout_form_31').val(),          
      32 : $('#wpsc_checkout_form_32').val(),
      33 : $('#wpsc_checkout_form_33').val(),
      34 : $('#wpsc_checkout_form_34').val(),
      35 : $('#wpsc_checkout_form_35').val(),
      36 : $('#wpsc_checkout_form_36').val(),          
      37 : $('#wpsc_checkout_form_37').val(),          
      38 : $('#wpsc_checkout_form_38').val(),
      39 : $('#wpsc_checkout_form_39').val(),
      40 : $('#wpsc_checkout_form_40').val(),              
      41 : $('#wpsc_checkout_form_41').val(),          
      42 : $('#wpsc_checkout_form_42').val(),
      43 : $('#wpsc_checkout_form_43').val(),
      44 : $('#wpsc_checkout_form_44').val(),
      45 : $('#wpsc_checkout_form_45').val(),
      46 : $('#wpsc_checkout_form_46').val(),          
      47 : $('#wpsc_checkout_form_47').val(),          
      48 : $('#wpsc_checkout_form_48').val(),
      49 : $('#wpsc_checkout_form_49').val(),          
      }

Can someone suggest a cleaner way of doing this, that would also account for any numbers higher than 49 if they do at some point get created by the user.

  • 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-01T14:04:07+00:00Added an answer on June 1, 2026 at 2:04 pm

    If you really must use object for this purpose, and your input val ID has that format, you can:

    var collected = {};
    $('input[id^=wpsc_checkout_form_]').each(function(i) {
       collected[i] = $(this).val();
    });
    
    $.post('/your/url', collected, function(resp) {
       // handler
    });
    

    Or you can use .serialize()

    $('#formId').serialize()
    

    http://api.jquery.com/serialize/

    The .serialize() method creates a text string in standard URL-encoded
    notation. It operates on a jQuery object representing a set of form
    elements. The form elements can be of several types

    Then in your ajax:

    $.post('url.php', $('#formId').serialize(), function(responseText) {
       // handler
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a contact form that can be hidden using .slideToggle() but I want
I have a dynamic form that is to be displayed using an iPad. This
I want to submit a form that have many checkboxes with different values, using
I have a form that allows a user to add an unlimited number of
I have a basic form that I'm using for member registration. I'm using the
this is a simple question. I have a form that is being validated using
(Using MySQL and PHP) I have a search form that will allow my users
I have a form on a webpage that I submit using the jquery form
I have started using jQuery and rails. I have made a simple form that
I have a label that is using a repeater to get information form a

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.