Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays of textboxes, and getting there values 1

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
US
i would like to have an array of textboxes and would like to put the values of all the textboxes in an array. Does anyone have a example of this? or can point me in the right direction. Im not quite sure on how to do this, if the textboxes names can be all alike, and so on.
 
Name all of your textboxes the same thing on the form, and then, on the server-side processing, do this:

Dim ar_strNames
Dim intElements
ar_strNames = Split(Request.Form("name"), ", ")
intElements = UBound(ar_strNames)

This will take all form values named "name" and put them in an array. Then, the number of elements is saved to the intElements variable.

Hope this is what you want. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Will the same code work for a multidimentional array??
 
If you format it correctly, then yes. I'm not sure what or why you want to do it, but it is possible. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Im sorry for not explaining this throughly enough, i have a purchase order page w/ 30 sets of textboxes; quantity, item number, item description, price. I want to put whatever the user puts into the textboxes into a database. I figured the best way would be to use a array, any ideas of a better way to go about this problem, Thanks!
 
an alternative method could be to name a related group of text fields with the same name:
eg product_name

<tr>
<td>One
<input type=&quot;text&quot; name=&quot;product_name&quot; value=&quot;&quot;>
</td>
</tr>

<tr>
<td>Two
<input type=&quot;text&quot; name=&quot;product_name&quot; value=&quot;&quot;>
</td>
</tr>

then when you submit the form access the values in these fields from the Request object with code like

arrNames = Split( Request(&quot;product_name&quot;), &quot;,&quot; )

As all the product_name fields will be passed as a comma delimited string you can split them into an array. You would then have the values.

I hope this helps



 
That is the method that I suggested above.

I believe this is the best method. I would create an array for each set of textboxes, tho, and not one to hold everything. If you want, it is possible, but having an array var name is more descriptive than using an array index. Just my suggestion.

If you do want to do this, just name all of the groups the same: txtSize, txtColor, etc. Then, use the Split function to split up the array elements. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
Thanks for all the help, my only problem now is, how about someone enters a &quot;,&quot; in a textbox, then it messes up the split. Can i delimit the field w/ a * or something similar, then the form is submitted. Thanks again!
 
you could overcome this by doing a replace before doing the split

eg.

strNames = Replace(strNames, &quot;,&quot; , &quot;&quot; )

this would replace the ',' with nothing

Hope this helps
 
Forgive me for being a newbie, but this is the code i have that occurs after the initial page is submitted,

<%
Dim Quantity(30)
Dim Item_Number(30)
Dim Item_Description(30)
Dim Charge_To_Company(30)
Dim Charge_To_GL(30)
Dim Item_Unit_Cost(30)


arrQuantity = Replace(arrQuantity,&quot;,&quot; ,&quot;&quot; )
arrItem_Number = Replace(arrItem_Number, &quot;,&quot; , &quot;&quot; )
arrItem_Description = Replace(arrItem_Description,&quot;,&quot; ,&quot;&quot; )
arrCharge_To_Company = Replace(arrCharge_To_Company,&quot;,&quot; ,&quot;&quot; )
arrCharge_To_GL = Replace(arrCharge_To_GL,&quot;,&quot; ,&quot;&quot; )
arrItem_Unit_Cost = Replace(arrItem_Unit_Cost,&quot;,&quot; ,&quot;&quot; )



arrQuantity = Split( Request(&quot;Quantity&quot;), &quot;,&quot; )
arrItem_Number = Split( Request(&quot;Item_Number&quot;), &quot;,&quot; )
arrItem_Description = Split( Request(&quot;Item_Description&quot;), &quot;,&quot; )
arrCharge_To_Company = Split( Request(&quot;Charge_To_Company&quot;), &quot;,&quot; )
arrCharge_To_GL = Split( Request(&quot;Charge_To_GL&quot;), &quot;,&quot; )
arrItem_Unit_Cost = Split( Request(&quot;Item_Unit_Cost&quot;), &quot;,&quot; )
%>

<HTML>
<HEAD><TITLE>Confirmation</TITLE></HEAD>
<BODY>

<% Response.Write arrQuantity(0) %>,
<% Response.Write arrItem_Number(0) %>,
<% Response.Write arrItem_Description(0) %>,
<% Response.Write arrCharge_To_Company(0) %>,
<% Response.Write arrCharge_To_GL(0) %>,
<% Response.Write arrItem_Unit_Cost(0) %>,
<BR>
<% Response.Write arrQuantity(1) %>,
<% Response.Write arrItem_Number(1) %>,
<% Response.Write arrItem_Description(1) %>,
<% Response.Write arrCharge_To_Company(1) %>,
<% Response.Write arrCharge_To_GL(1) %>,
<% Response.Write arrItem_Unit_Cost(1) %>,




</BODY>
</HTML>

I know that the replace statement is wrong since i am doing a replace on a array rather than a string. I tried doing a for loop to no avail. Any help is greatly appriciated, Thanks
 
The comma will need to be replaced before the page is ever submitted, otherwise you will simply be killing all the commas in your field and when you go to do a split you will end up with arrays with only a single long item.

Option 1) What you could do is use the onSubmit client side event in the form tag to loop through your collection replacing the commas with something significant (like *COMMA*). Then after you have split the array on the following page and you are assign the array items into sql strings or variables, simply do a Replace(strname, &quot;*COMMA*&quot;,&quot;,&quot;)

Option 2) Since multiple items are passed delimited with a comma space, you can use the above method, but instead of replacing commas with an identifier, you could replace any comma-space with a comma. That way when it is passed you could simply split on &quot;, &quot; (comma-space) and it will ignore any commas the user typed because they will not be followed by spaces.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
Can't...think...of...anything...funny...to.........say............
need.....coffee....................
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top