Link to home
Start Free TrialLog in
Avatar of Tim Titus
Tim TitusFlag for United States of America

asked on

How do you transmit an array back to the server via an HTML form?

Is it possible to send an array through an HTML form back to a server?  I don't know the number of elements in the array, as the user will decide how many elements to report to the server.

I will be using the FORM method=POST so it can handle larger amounts of data.

I'm using IIS on the server side if that makes any difference.
Avatar of gamebits
Flag of Canada image

I don't know what server language you use to handle the form but in php it would be a pair of bracket after the form element name

<input type="text" name="somename[]" size="15">

Not through HTML.  HTML isn't a language and doesn't have ANY variables.  You can place the contents of the array in the html code and then recover it with some scripting language but this would require some server script.  Even Javascript can't do anything on the server without help from server script.

Let me know if you have any questions or need more information.  If you need more details then please provide more info.  The question and info is pretty vague and general.

Avatar of Tim Titus


My apology for the vague question -- I'm not skilled in this area.

I would like to have an HTML form POST "X" variables.  The user would select how many fields to fill in (from 0 to 100) and then submit all of the filled in fields.

Since the page does not know how many fields will be initially submitted, I figured that you would use JavaScript to retrieve the information and store it to an array.  When the user clicks "submit", the form would send the array back to the server for processing.

What is the most efficient way to get this information back to the server when you don't know how many variables will be sent back?
Thanks for those details and the info.

What is your server language that will process the form?  Will there always be 100 fields or is the form "made" with the fields they select (i.e. from a previous page or dynamically)?

I wouldn't depend on Javascript to keep track of the number unless Javascript is used to make the inputs.  If you use PHP then provide each field the same name and have it end with [] (e.g. name="field[]").  Doing that will have PHP automatically create an array or collection named field with all of the values.  In other cases just use a hidden field to store the number.  Get that value and then use it for the loop (e.g. field1 - field40).

Let me know if you have a question or need more info.

I'm planning on having a coder build the server side with IIS and ASP.NET technology and am trying to make it easy for them to handle receiving a variable number of fields.

The form will always have 2 fields that are submitted (customer number and customer location), and will have 0 to ??? number of messages that would be passed.  Each message would be a string.

Sometimes there will be 0 messages to pass.  Sometimes there might be 1000 messages (or more) to be passed.

I figure if the HTTP POST had an array for the messages, the server side could easily loop through the returned messages and process each of them.
Avatar of b0lsc0tt
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please explain the B grade.  Did you still have a question or need help with this?  Was there a mistake as you closed this?  Let me know if either is the case.

If you have a question about grades and what they mean then look at .  Keep in mind you only offered 50 points for this too.  I just can't understand why you would close this with a B after all the details and info I provided.  Please explain the grade.  It is nice to have a chance to earn the A or at least know why it wasn't.  In this case it seems like the A was earned.

Sorry!  I posted this in the wrong comment.

Thanks for the grade, the points and the fun question.  Please forget the comment above and forgive me.  I got this mixed up. :)