Forum Moderators: open
mypage.asp?list=Sam
Sam was selected as the item from the drop down box.
However, when multiple is allowed in the select the resulting querystring looks like this:
mypage.asp?list=Sam&list=Dave&list=Sue
This is not very good for submitting data or working with queries at all.
I was able to write some javascript to intercept the form submission and use a "location.href=" instead of a submit, but that's not very reliable. My new querystring looked like this:
mypage.asp?list=Sam¦Dave¦Sue
which is fine to use. I can parse it in my destination page and do something with the different parts of the data.
How do other people handle the "multiple" in a form submission? (Other than using checkboxes - I already do that in one application)
<select multiple="" name="list[]">
... list options here ...
</select>
Like I said, I don't know if this works with other scripting languages, but it seems reasonable.
the same is explained in the PHP documentation in the section on Variables from outside PHP [php.net] as well. It works great and I have been using it for years now.
Andreas
all in all I don´t think it is a good idea to mess around with the way data are submitted by the browser. If you don´t like the long query string you should post the data.
I´m sure ASP has a way to handle multiple selects and store them in an array just as PHP or Lincoln Stein´s CGI.pm has.
Andreas
I found this works, then the values can be used in an SQL insert statement
I created a mypage.asp with the code below, then visited it using your query string
<%
'-- this first line just shows how the querystring
'-- is being read and is for information only
response.write Request.Querystring("list") & "<br /><br />"
'-- dim the querystring to a variable
Dim varArray
varArray = request.querystring("list")
'-- split the array, using the comma as delimiter
varItems = split(varArray, ",")
'-- loop through the list
For Each Item in varItems
value = trim(item)
Response.Write value & "<br />"
'-- hopefully you are getting the values,
'-- and can now change the response.write to an sql insert statement
NEXT
%>
HTH
Suzy
name=fred&name=harv&name=sue&name=bill
The Request.QueryString("name") would freak out at that.
I want to send the data in the form as name=fred¦harv¦sue
bill
I suppose I could try to do it by reading the entire querystring in the receiving page, but that would be a much trickier proposition than what I'm doing now.
I'll post the question on an ASP board and see what shakes out.
anyhow if that's the way (name = sam¦dave¦sue) you want to send the data it's even easier
<%
'-- dim the querystring to a variable
Dim varArray
varArray = request.querystring("list")
'--this will produce the variable you're looking for
name = Replace(varArray, "," , "¦")
'-- just to test
response.write name
%>
Suzy
The Request.QueryString("name") would freak out at that.
Why would it? Have a look at Microsoft´s documentation of the Request.QueryString Collection [msdn.microsoft.com].
The value of Request.QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING.
Andreas