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("ListBox")),
I get the list of selected values, separated by commas.
Christina 26 31548
if you then split that list into an array yo then only need a simple loop to
grab 'em all:
myarray=split(Request.Form("ListBox"))
for n=0 to ubound(myarray)
' ... now each of the items is accessed as ;
myarray(n)
next
"Christina" <ha********@hotmail.con> wrote in message
news:eN**************@TK2MSFTNGP09.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("ListBox")), 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("Listbox")
''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake
ArrayOfValues = Split(sVal, ", ")
For i = 0 To UBound(ArrayOfValues)
Response.Write "Value " & i & " is " & ArrayOfValues(i) & "<br>"
Next
%>
Ray at work
"Christina" <ha********@hotmail.con> wrote in message
news:eN**************@TK2MSFTNGP09.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("ListBox")), I get the list of selected values, separated by commas.
Christina
of course that should read
myarray=split(Request.Form("ListBox"),",")
soz
"UncleWobbly" <he***@talk21.com> wrote in message
news:40*********************@lovejoy.zen.co.uk... if you then split that list into an array yo then only need a simple loop
to grab 'em all:
myarray=split(Request.Form("ListBox"))
for n=0 to ubound(myarray) ' ... now each of the items is accessed as ; myarray(n) next
"Christina" <ha********@hotmail.con> wrote in message news:eN**************@TK2MSFTNGP09.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("ListBox")), I get the list of selected values, separated by commas.
Christina
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.Form("Listbox")
Response.Write "<td>" & Replace(sVal,", ","</td><td>") & "</td>"
%>
</tr>
</table>
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:%2****************@TK2MSFTNGP11.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("Listbox") ''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake
ArrayOfValues = Split(sVal, ", ")
For i = 0 To UBound(ArrayOfValues) Response.Write "Value " & i & " is " & ArrayOfValues(i) & "<br>" Next %>
Ray at work "Christina" <ha********@hotmail.con> wrote in message news:eN**************@TK2MSFTNGP09.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("ListBox")), I get the list of selected values, separated by commas.
Christina
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******************@TK2MSFTNGP09.phx.gbl... "UncleWobbly" wrote: : of course that should read : : myarray=split(Request.Form("ListBox"),",")
or: myarray=split(Request.Form("ListBox"),", ") ...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
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... "Christina" <ha********@hotmail.con> wrote in message news:eN**************@TK2MSFTNGP09.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("ListBox")), 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("Listbox") ''sVal = "Joe, Bob, Tom, Phil, Toby" for argument's sake
ArrayOfValues = Split(sVal, ", ")
For i = 0 To UBound(ArrayOfValues) Response.Write "Value " & i & " is " & ArrayOfValues(i) & "<br>" Next %>
Ray at work
I believe Request.Form(Key) is already an array (sort of):
<%
Dim i,iMax
iMax = Request.Form("test").Count
For i = 1 To iMax
Response.Write Request.Form("test")(i) & "<br>"
Next
%>
<form method="post">
<select name="test" multiple="multiple">
<option value="apple">apple</option>
<option value="banana">banana</option>
<option value="cranberry">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
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**************@TK2MSFTNGP11.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******************@TK2MSFTNGP09.phx.gbl... "UncleWobbly" wrote: : of course that should read : : myarray=split(Request.Form("ListBox"),",")
or: myarray=split(Request.Form("ListBox"),", ") ...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
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
"UncleWobbly" <he***@talk21.com> 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**************@TK2MSFTNGP11.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******************@TK2MSFTNGP09.phx.gbl... "UncleWobbly" wrote: : of course that should read : : myarray=split(Request.Form("ListBox"),",")
or: myarray=split(Request.Form("ListBox"),", ") ...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
Thank you all for good help!! :)
This worked:
myArray = Request.Form("ListBox").Split(",")
For i = 0 To UBound(myArray)
Response.Write(myArray.GetValue(i))
Next
Hugs,
Christina
"Christina" <ha********@hotmail.con> wrote in message
news:eN**************@TK2MSFTNGP09.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("ListBox")), I get the list of selected values, separated by commas.
Christina
Hello Christina,
I don't know in what environment you are programming but you might be able to use this HTML and JavaScript code to show how to separate the comma separated list into an array. The split() method creates an array of elements from a String object by using the delimiter specified in its parameter. The code may not be perfect because I wrote it during my computer lab class in college so maybe there can be some improvements. I am just showing you an idea. Use the array then to fill up a table.
Signed,
BusyMan
CODE******************************************
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
var sampleText="red,green,blue,violet";
function getWords() {
var input = sampleText.split(",");
var input2 = new String();
for (var i = 0; i<input.length; i++) {
input2 += input[i] + "<BR>";
}
document.all("HERE").innerHTML = input2;
}
</SCRIPT>
</HEAD>
<BODY onLoad="getWords()">
<SPAN ID="HERE"></SPAN>
</BODY>
</HTML>
************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
:o))))))))))))))))))))
none of thought of that one!!!
LOL!
"Christina" <ha********@hotmail.con> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl... Thank you all for good help!! :) This worked:
myArray = Request.Form("ListBox").Split(",") For i = 0 To UBound(myArray) Response.Write(myArray.GetValue(i)) Next
Hugs, Christina
"Christina" <ha********@hotmail.con> wrote in message news:eN**************@TK2MSFTNGP09.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("ListBox")), I get the list of selected values, separated by commas.
Christina
:o)
not yet you aren't... see Christina's final solution :o)
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:ul**************@TK2MSFTNGP12.phx.gbl... 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
"UncleWobbly" <he***@talk21.com> 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**************@TK2MSFTNGP11.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******************@TK2MSFTNGP09.phx.gbl... > "UncleWobbly" wrote: > : of course that should read > : > : myarray=split(Request.Form("ListBox"),",") > > or: > myarray=split(Request.Form("ListBox"),", ") > ...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 > >
"Christina" <ha********@hotmail.con> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl... This worked:
myArray = Request.Form("ListBox").Split(",") For i = 0 To UBound(myArray) Response.Write(myArray.GetValue(i)) Next
That worked? What language is this? VBJscript? ? ? ?
Ray at work
Christina wrote: Thank you all for good help!! :) This worked:
????
How could this possibly work? myArray = Request.Form("ListBox").Split(",")
A JScript function, Split(), followed by
For i = 0 To UBound(myArray)
A vbcript-style loop through an array using a vbscript function, ubound()
followed by
Response.Write(myArray.GetValue(i))
another jscript function, GetValue(), which is syntactically incorrect
(getValue() is correct) to get the value of the array element!
Next
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
On Thu, 29 Jan 2004 15:58:31 -0500, "Ray at <%=sLocation%> [MVP]"
<myfirstname at lane34 dot com> wrote: "Christina" <ha********@hotmail.con> wrote in message news:ug**************@TK2MSFTNGP11.phx.gbl...
This worked:
myArray = Request.Form("ListBox").Split(",") For i = 0 To UBound(myArray) Response.Write(myArray.GetValue(i)) Next
That worked? What language is this? VBJscript? ? ? ?
Now if there were a VBPB&Jscript that would also trim the cursts I'd
be impressed... :)
Actually, I am impressed with Christina's solution. I don't know
enough to say why it works, but it opens possibilities I hadn't
considered before. Good work.
Jeff
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:40***************@msnews.microsoft.com... Actually, I am impressed with Christina's solution. I don't know enough to say why it works, but it opens possibilities I hadn't considered before.
What is going on here? Since when does request.form have a split method?
Is today April 1st? Did I miss a post somewhere or something?
Ray at work
On Thu, 29 Jan 2004 16:30:56 -0500, "Ray at <%=sLocation%> [MVP]"
<myfirstname at lane34 dot com> wrote: "Jeff Cochran" <jc*************@naplesgov.com> wrote in message news:40***************@msnews.microsoft.com...
Actually, I am impressed with Christina's solution. I don't know enough to say why it works, but it opens possibilities I hadn't considered before.
What is going on here? Since when does request.form have a split method? Is today April 1st? Did I miss a post somewhere or something?
It doesn't. Which is kinda the beauty of it. It uses a method that
isn't there. Very Zen. Hmmm... Don't code the method, *Be* the
method... :)
Nuts, you're right. It isn't April 1...
Jeff
"Christina" <ha********@hotmail.con> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
: Thank you all for good help!! :)
: This worked:
:
: myArray = Request.Form("ListBox").Split(",")
: For i = 0 To UBound(myArray)
: Response.Write(myArray.GetValue(i))
: Next
It's a new language, all it's own. (see undocumented feature set)
What will Christina come up with next? (O:=
Roland (confused - as I should be)
"Bob Barrows" wrote: myArray = Request.Form("ListBox").Split(",")
A JScript function, Split(), followed by
Unless [Split] is a method of the Request.Form object, even JScript won't
like this, though JScript will certainly be happy with
myArray = Request.Form("ListBox").Item.split(",")
....since R.F().Item is a string value.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
It seems to me that it works like this: request.form("x") returns a
string. The string has the split method.
-rwg
This is what I think, not necessarily what is right
In jscript, strings are objects and have methods. In VBscript, they do not.
The code she posted had a mixture of vbscript and jscript and some third
language I've never seen.
Ray at work
"Rob Greene" <a-****@online.microsoft.com> wrote in message
news:$%****************@cpmsftngxa07.phx.gbl... It seems to me that it works like this: request.form("x") returns a string. The string has the split method.
-rwg This is what I think, not necessarily what is right
"Rob Greene" wrote: It seems to me that it works like this: request.form("x") returns a string. The string has the split method.
Request.Form("x") is not a string value, nor a String Object. It is an
object with properties .Key, .Count and .Item. It has no native .Split()
method.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Dave Anderson wrote on 02 feb 2004 in
microsoft.public.inetserver.asp.general: "Rob Greene" wrote: It seems to me that it works like this: request.form("x") returns a string. The string has the split method.
Request.Form("x") is not a string value, nor a String Object. It is an object with properties .Key, .Count and .Item. It has no native .Split() method.
So:
arr = request.form("x").item.split(",")
?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl... "Rob Greene" wrote: It seems to me that it works like this: request.form("x") returns a string. The string has the split method. Request.Form("x") is not a string value, nor a String Object. It is an object with properties .Key, .Count and .Item. It has no native
..Split() method.
I don't believe that Request.Form("x") supports the Key property. The
Request object is immutable.
-Chris Hohmann
"Evertjan." wrote: arr = request.form("x").item.split(",")
?
JScript is case sensitive. That should be
Request.Form("x").Item.split(",")
And if you're unsure if there will even be a name-value pair for "x", you
can use this:
(Request.Form("x").Item || "").split(",")
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by middletree |
last post: by
|
5 posts
views
Thread by Morris |
last post: by
|
5 posts
views
Thread by Derek |
last post: by
|
32 posts
views
Thread by Toby Newman |
last post: by
|
3 posts
views
Thread by Avi |
last post: by
|
2 posts
views
Thread by ILCSP |
last post: by
|
6 posts
views
Thread by Drum2001 |
last post: by
|
5 posts
views
Thread by hprYeV |
last post: by
|
1 post
views
Thread by silverburgh.meryl |
last post: by
| | | | | | | | | | | |