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!

Determining List Box Contents in ASP 2

Status
Not open for further replies.

adknbvi

Programmer
Apr 17, 2001
25
0
0
US

Hello,
I have a listbox of &quot;selected items&quot; that is dynamically filled by the user (by choosing items off an &quot;Everything that's available&quot; listbox). You've seen these with the &quot;<&quot; and &quot;>&quot; buttons to put things on the user's personal list and then remove them later.

Via ASP, how do I know the contents of the listbox when I have posted the form and am trying to read the contents via Request.Form().

If I can't do it, should I build a comma-delimited list in a hidden input box prior to leaving the first page?

Thanks in advance,
Valerie
 
I'm assuming that this is a multiple selection input box, so there is an easy way to do this.

a multiple selection input box is a collection, so all you need to do is iterate through the collection to get everything you need.

ex:
<%
Dim myinput(), i
redim myinput(request.form(&quot;myinput&quot;).count)
i = 0
for each item in request.form(&quot;myinput&quot;)
myinput(i) = item.value
i = i + 1
next
%>

this should build you an array, called myinput, containing all the selections from your multiple input box.

hope this helps
leo
 
Leo,
I'm sorry to bother you again. I should have mentioned in my first post that I am working in JavaScript. What is the JavaScript equivalent for &quot;for each item in....&quot;? I have tried assuming the results were a string and using the .split method to form an array, but that hasn't worked.

Any help would be greatly appreciated!
Valerie
 
Since the list now resides only client side and in Javascript, you need to send it back to ASP. Here is an example of one we've used:
//create the list as comma delimited
var listtext = &quot;&quot;;
var i;
var j = document.FormList.list1.options.length;
for(var i=0; i<j; i++) {
listtext += document.FormList.list1.options.value;
if ( i +1 < j ) {
listtext += &quot;,&quot;;
}
}

URL += &quot;page.asp?listboxinfo=&quot;+listtext;
//now sending the page with the list back to the page.asp with the list in the query string
self.location = URL;

You can pull the data from the query string.

Hope that helps,
Joli
 
Joli,
Thank you! That was very helpful! I am now moving forward again!
Valerie
 
My fellow colegs are right...
but...
This is a server side example of getting the values of
multiple selections in JScript

Here is an example of JScript asp side

process.asp
<%@ Language=JScript %>
<%
nrval=Request.Form(&quot;options&quot;).Count;
for(i=1;i<=nrval;i++)
{
%>
Request.Form(&quot;txt&quot;)(<%=i%>)=<%=Request.Form(&quot;txt&quot;)(i)%><br>
<%
};
%>

and the
page.htm

<HTML>
<BODY>
<form action=&quot;process.asp&quot; method=&quot;post&quot;>
<select name=&quot;options&quot; multiple>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
<option value=&quot;3&quot;>3
<option value=&quot;4&quot;>4
<option value=&quot;5&quot;>5
</select>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1></form>
</BODY>
</HTML>

This is used without an hidden text to pass the multiple select from page.htm
________
George, M
email : shaddow11_ro@yahoo.com
 
Sorry one error
Replace the line
Request.Form(&quot;txt&quot;)(<%=i%>)=<%=Request.Form(&quot;txt&quot;)(i)%><br>

With
Request.Form(&quot;options&quot;)(<%=i%>)=<%=Request.Form(&quot;options&quot;)(i)%><br>

________
George, M
email : shaddow11_ro@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top