473,657 Members | 2,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I loop through a comma-separated list?

I have a post-form that holds a listbox with mulitple selected items. When
the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?

If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina
Jul 19 '05 #1
26 32112
if you then split that list into an array yo then only need a simple loop to
grab 'em all:

myarray=split(R equest.Form("Li stBox"))

for n=0 to ubound(myarray)
' ... now each of the items is accessed as ;
myarray(n)
next
"Christina" <ha********@hot mail.con> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
I have a post-form that holds a listbox with mulitple selected items. When
the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?

If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina

Jul 19 '05 #2
I believe that the items are probably separated by a comma and a space
actually, yes? What you'd want to do is create an array.

<%
sVal = Request.Form("L istbox")
''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake

ArrayOfValues = Split(sVal, ", ")

For i = 0 To UBound(ArrayOfV alues)
Response.Write "Value " & i & " is " & ArrayOfValues(i ) & "<br>"
Next
%>

Ray at work


"Christina" <ha********@hot mail.con> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
I have a post-form that holds a listbox with mulitple selected items. When
the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?

If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina

Jul 19 '05 #3
of course that should read

myarray=split(R equest.Form("Li stBox"),",")

soz

"UncleWobbl y" <he***@talk21.c om> wrote in message
news:40******** *************@l ovejoy.zen.co.u k...
if you then split that list into an array yo then only need a simple loop to grab 'em all:

myarray=split(R equest.Form("Li stBox"))

for n=0 to ubound(myarray)
' ... now each of the items is accessed as ;
myarray(n)
next
"Christina" <ha********@hot mail.con> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?

If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina


Jul 19 '05 #4
"UncleWobbl y" wrote:
: of course that should read
:
: myarray=split(R equest.Form("Li stBox"),",")

or:
myarray=split(R equest.Form("Li stBox"),", ")
....if there is actually a space in it as Ray mentioned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #5
While admittedly Ray's solution is the correct one. If you are just putting
them in a table, you could do something like....

<table>
<tr>
<%
sVal=Request.Fo rm("Listbox")
Response.Write "<td>" & Replace(sVal,", ","</td><td>") & "</td>"
%>
</tr>
</table>

"Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I believe that the items are probably separated by a comma and a space
actually, yes? What you'd want to do is create an array.

<%
sVal = Request.Form("L istbox")
''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake

ArrayOfValues = Split(sVal, ", ")

For i = 0 To UBound(ArrayOfV alues)
Response.Write "Value " & i & " is " & ArrayOfValues(i ) & "<br>"
Next
%>

Ray at work


"Christina" <ha********@hot mail.con> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?

If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina


Jul 19 '05 #6
What I'm wondering is if the separator is done by the server or if the
browser chooses the delimiter and posts the data with it. I ~believe~ that
the browser submits data like:

select=a&select =b&select=c, etc. and it's the ASP process that returns that
as comma+space delimited values.

Ray at work
"Roland Hall" <nobody@nowhere > wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
"UncleWobbl y" wrote:
: of course that should read
:
: myarray=split(R equest.Form("Li stBox"),",")

or:
myarray=split(R equest.Form("Li stBox"),", ")
...if there is actually a space in it as Ray mentioned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 19 '05 #7
"Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
"Christina" <ha********@hot mail.con> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the selected items, to insert each of them into a table. How do I do that?
If I execute the line:
Response.Write( Request.Form("L istBox")),
I get the list of selected values, separated by commas.
Christina

I believe that the items are probably separated by a comma and a space
actually, yes? What you'd want to do is create an array.

<%
sVal = Request.Form("L istbox")
''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake

ArrayOfValues = Split(sVal, ", ")

For i = 0 To UBound(ArrayOfV alues)
Response.Write "Value " & i & " is " & ArrayOfValues(i ) & "<br>"
Next
%>

Ray at work


I believe Request.Form(Ke y) is already an array (sort of):

<%
Dim i,iMax
iMax = Request.Form("t est").Count
For i = 1 To iMax
Response.Write Request.Form("t est")(i) & "<br>"
Next
%>
<form method="post">
<select name="test" multiple="multi ple">
<option value="apple">a pple</option>
<option value="banana"> banana</option>
<option value="cranberr y">cranberry </option>
<option value="danish"> danish</option>
<option value="egg">egg </option>
</select>
<input type="Submit">
</form>

The documentation states as much. However, what is not made clear is
that there is an implicit translation to a string when a form variable
is referenced. As such the following fails with a type mismatch:

UBound(Request. Form("test"))

Here's a link to the documentation:
http://msdn.microsoft.com/library/en...bom_reqocf.asp
HTH
-Chris
Jul 19 '05 #8
play safe and trim the items in the array as they are used :o)
"Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
news:ez******** ******@TK2MSFTN GP11.phx.gbl...
What I'm wondering is if the separator is done by the server or if the
browser chooses the delimiter and posts the data with it. I ~believe~ that the browser submits data like:

select=a&select =b&select=c, etc. and it's the ASP process that returns that as comma+space delimited values.

Ray at work
"Roland Hall" <nobody@nowhere > wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
"UncleWobbl y" wrote:
: of course that should read
:
: myarray=split(R equest.Form("Li stBox"),",")

or:
myarray=split(R equest.Form("Li stBox"),", ")
...if there is actually a space in it as Ray mentioned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -

http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Jul 19 '05 #9
Actually, I think I now prefer the method Chris posted, because if one of
your option values is "B, C" that'll be split. I am so finished with
splitting multi-element form controls! :]

Ray at work

"UncleWobbl y" <he***@talk21.c om> wrote in message
news:40******** *************** @lovejoy.zen.co .uk...
play safe and trim the items in the array as they are used :o)
"Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
news:ez******** ******@TK2MSFTN GP11.phx.gbl...
What I'm wondering is if the separator is done by the server or if the
browser chooses the delimiter and posts the data with it. I ~believe~

that
the browser submits data like:

select=a&select =b&select=c, etc. and it's the ASP process that returns

that
as comma+space delimited values.

Ray at work
"Roland Hall" <nobody@nowhere > wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
"UncleWobbl y" wrote:
: of course that should read
:
: myarray=split(R equest.Form("Li stBox"),",")

or:
myarray=split(R equest.Form("Li stBox"),", ")
...if there is actually a space in it as Ray mentioned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -

http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3392
by: middletree | last post by:
I have a page where I allow the user to select one or more names of employees to send an email to, which is sent automatically when the form is submitted. I have a field called EmailSentTo, and if you sent it to Joe Smith, then it stores the employee's number, 200, which is the PK of the Employee table. And there is, of course, another page which displays all the information from that form I just submitted, so I want to display this new...
5
1749
by: Morris | last post by:
This may not be possible on the server side, so apologies if this is the wrong group for this post. My form consists of an unknown number of pairs of text boxes. They are named textbox_a and textbox_b. I then split the comma separated list that gets posted: textbox_a = split(Request.Form("textbox_a"),",") for i = ubound(textbox_a) ...insert into db
5
2559
by: Derek | last post by:
I came upon the idea of writting a logging class that uses a Python-ish syntax that's easy on the eyes (IMO): int x = 1; double y = 2.5; std::string z = "result"; debug = "Results:", x, y, z; The above example outputs:
32
4632
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it offers."
3
7112
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then export it into a text file. Is there any s/w out there I could use? I am not much of a programmer but I heard I could use VBA to get this done. Any help with the code will be appreciated. Thanks
2
9168
by: ILCSP | last post by:
Hi, I have a sql table containing the answers for some tests. The information in this table is presented vertically and I need to create strings with them. I know how to read the data in VB.Net and use a StreamWriter to build the strings. However, the problem lies with the reading of each row. Most of the test takers don't give answers to ALL of the items in a test, but those unanswered items need to be accounted for by using a comma...
6
2094
by: Drum2001 | last post by:
I have a database where I need to query multiple items. Is it possible to run a query based on a textbox where the information is delimited by a comma. Example: Show me all names where Social Security Number: = 111223333, 444556666, 777889999
5
4002
by: hprYeV | last post by:
I have done a reasonable amount of programming in C++, but the other day I was talking to someone after a lecture in a course on Java who said that they had not been used to the syntax of the Java for loop because they always had been programming in C++. I asked them what it was they had not been used to, and they said that in C++ you can use commas to separate the initial statement, the condition, and the loop statement like this: ...
1
1901
by: silverburgh.meryl | last post by:
Hi, I need some help in understanding the following for() loop: for (PRBool isRoot; mCSSUtils->IsRuleNodeRoot(ruleNode, &isRoot), !isRoot; mCSSUtils->GetRuleNodeParent(ruleNode, &ruleNode)) what is the middle clause for? Why there is a ',' in the middle? And what does that mean?
4
4332
anfetienne
by: anfetienne | last post by:
hi im back again.......i have a code to create strings and save it within a text file to pass variables to flash. im using the string format below. mylist=apple,cherry,lemon,banana&mylist2=apple,cherry,lemon,banana this code below is what im using to write my string to the text file, basically the info is collected from a db and i use a loop to cycle through and write each value in. I have to seperate these values using a comma ','...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.