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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:34:01+00:00 2026-05-25T18:34:01+00:00

I want to create a javascript form that basically has a bunch of text

  • 0

I want to create a javascript form that basically has a bunch of text input boxes. But I want the number of boxes to be the value of some variable, and I would like the id’s or the names of the boxes to be elements in one array.

Actually, any solution to the following problem would be great. I have some variable x, and if x=10 then the form will be ten text input boxes, and at the end of the day (when the user clicks on the button to say “I’ve finished filling in these boxes now”) I can create an array of length 10 whose entries are the contents of the ten text input boxes. But if x was 3 then there would be three text input boxes and I end up with an array of length 3 etc etc.

My current work-around, which is awful, currently involves 50 text input boxes, with names box01 to box50, and then 50 lines of the form a[1]=box01 a[2]=box02 etc etc, and the user can just leave all the ones he’s not interested in blank. But I would imagine that something more streamlined is possible!

  • 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-25T18:34:02+00:00Added an answer on May 25, 2026 at 6:34 pm

    To create the textboxes:

    var x = 10,
        str = '';
    while (x) {
      str = str + '<input type="text" name="box[]" id="box' + x + '">';
      x = x - 1;
    }
    

    Then you have a string str which you can insert in to the DOM. Because the name attribute is an ‘array’ (the square brackets mean “the value of this input is an element of the box array”).

    On the server side, you can then loop through this array. In PHP:

    foreach ($_POST['box'] as $box) {
      // do something with the input value
    }
    

    The foreach will loop through $_POST['box'] (which is an array, because we used those square brackets), and you can do whatever you like with each box value inside the loop.

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

Sidebar

Related Questions

I want to create a input textbox that does not require a <input type=text>
I want to create a string in JavaScript that contains all ascii characters. How
Basically I want to create one large object of many object in JavaScript. Something
Say I want to create a form that allows you to add elements dynamically
Basically, I referred to some sources, and found this: Yah, that's easy, just create
I have a form that has hidden elements in it to create a pseudo-array
I want to create a compiled JavaScript file for my website. For development I
I want to create a draggable and resizable window in JavaScript for cross browser
I'm not sure how I would do this in Javascript. I want to create
I create a file in JavaScript. Now I want to be able to make

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.