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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In program-1 I have a collection of

Status
Not open for further replies.

glendacom

MIS
Oct 23, 2002
36
0
0
US
In program-1 I have a collection of checkboxes defining colors of lights (named "lights") as a part of a form being posted for use by program-2. When I access the value(s) of lights in program-2 it shows it as one long string (ex. yellow, red, orange). I used the split function to break this into three distinct colors which works just fine most of the time BUT. My problem is that some of the colors have a comma in their name. Is there a way to tell the form (?) to separate the colors with a different separator (maybe a percent sign)? Or is their some other way to access this list of values for a checkbox group?
 
No, unfortunatly, but if these are set as values i a checkbox then the user will never see the value and you can use any value you would like. You could even set up an array inside an include file like so:
Code:
colors.asp
<%
Dim colorArray(3)
colorArray(0) = &quot;Red&quot;
colorArray(1) = &quot;Blue&quot;
colorArray(2) = &quot;Green&quot;
colorArray(3) = &quot;Puce&quot;
%>

Then instead of using the word as the value for the checkbox you could create the text boxes on the fly and use the number:
Code:
<%
Option Explicit

'include the colors file to let it take care of your array
%><!--#INCLUDE FILE=&quot;colors.asp&quot; --><%

'all your other stuff like writing form tags and so on

Dim colorCtr
For colorCtr = 0 to UBound(colorArray)
   Response.Write &quot;<input type='checkbox' name=&quot;chkUserColor&quot; value='&quot; & colorCtr & &quot;'> &quot; & colorArray(ctr) & &quot;<br>&quot;
Next
%>

Now that all the checkboxes are written you will need to get them back on the next page:

Code:
<%
Option Explicit

'include the colors file to let it take care of your array
%><!--#INCLUDE FILE=&quot;colors.asp&quot; --><%

Dim userColors
'split on comma space because the form adds a comma-space as a delimiter, not a comma
userColors = Split(Request.Form(&quot;chkUserColor&quot;),&quot;, &quot;)

'Now lets print them all out:
Dim i

response.Write &quot;The user chose: <br>&quot;
For i = 0 to UBound(userColors)
   'use the choice as the array index for our colors array, but make sure we convert it to an integer value first
   Response.Write colorArray(cInt(userColors(i))) & &quot;<br>&quot;
Next

And tadaaaa! No more comma issues. In fact this will also let you bypass other wierd characters to if the issue should ever come up.

Hope this proves useful,
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top