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

populating arrays from a multi-select text box

Status
Not open for further replies.
Nov 29, 2001
72
US
I have a multi-select drop down text box that contains location IDs. I would like to extract the selections made and populate an array with them using VBScript. For example the drop down text box values selected are "1,3,5" after I have gathered the data with the statement -
locID = request.form("loctxt").

I have not been able to find any information on how to do this in MSDN or my personal library.

Is there a standard way, or will I have to wing it?

Thanks in advance,
Dave
 
<script language=vbScript>

function showSelect()
dim selectArr()
redim selectArr(0)
for n = 0 to document.myForm.mySelect.options.length - 1
if document.myForm.mySelect.options(n).selected then
redim preserve selectArr(ubound(selectArr)+1)
selectArr(ubound(selectArr)) = document.myForm.mySelect.options(n).value
end if
next
alert ubound(selectArr)
end function

</script>
<form name=&quot;myForm&quot;>
<select name=&quot;mySelect&quot; multiple>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
</select>

<input type=button value=&quot;check&quot; onClick=&quot;showSelect()&quot;>



</form> -----------------------------------------------------------------
&quot;C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.&quot;
- Bjarne Stroustrup

mikewolf@tst-us.com
 
I don't think I gave enough information.
This involves two ASP pages. THe first page allows the user to select the locations:

<TR>
<TD class=header><font face=verdana color=firebrick size=1><b>Location(s)</font></b></td>
<TD align=&quot;center&quot;><SELECT NAME = &quot;Loctxt&quot; style=&quot;WIDTH: 183px&quot; multiple>
<OPTION value=&quot;All&quot; selected>All</OPTION>
<%

Set rst = Server.CreateObject(&quot;ADODB.Recordset&quot;)
sSQL = &quot;SELECT * FROM Locations &quot; _
& &quot;ORDER BY headerID&quot;
rst.Open sSQL, cnn

Do While Not rst.EOF
Response.Write &quot;<OPTION value=&quot;
Response.Write rst(&quot;headerID&quot;)
Response.Write &quot; >&quot;
Response.Write rst(&quot;location&quot;)
Response.Write &quot;</OPTION>&quot;
rst.MoveNext
Loop
Response.write &quot;</select>&quot;
rst.Close
Response.Write &quot;</TD>&quot;
%>
</TR>

The second ASP page collects the information:

locID = Request.Form(&quot;Loctxt&quot;)

It is at this point that I want to create an array based on the value(s) in &quot;locID&quot;. For instance if the variant &quot;locID&quot; now has the value of &quot;1,3,5&quot; in it, how do I take that and create a one dimensional array containing those values?

Thanks in advance for your help,
Dave
 
Hold the phone, I just found my answer. It is the Split function. I simply take the common delimitered &quot;locID&quot; with the value of &quot;1,3,5&quot; and use the following statement:
locIDarry = Split(locID, &quot;,&quot;)
The creates an array:
locIDarry(0) = &quot;1&quot;
locIDarry(1) = &quot;3&quot;
locIDarry(2) = &quot;5&quot;

Thanks anyway for trying to help me solve my little problem. Tek Tips is the first place I go when I have a coding issue I can't resolve quickly on my own.

Thanks again,
Dave
 

<%
mySelect = request(&quot;myselect&quot;) a string with the select values
selectArr = split(myselect,&quot;,&quot;)an array for each element
response.write &quot;<br>&quot; & ubound(selectArr)
%> -----------------------------------------------------------------
&quot;C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.&quot;
- Bjarne Stroustrup

mikewolf@tst-us.com
 
Looks like I found the answer just before you posted your last reply. Thanks for your help anyway.

-Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top