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

How to Parse Request.Form 2

Status
Not open for further replies.

TheMatt

IS-IT--Management
Dec 18, 2001
4
US
I have an selection control on an form named "UserOptions". I want the user to select multiple options on it. I would like to iterate through the options that the user selected after the form is submitted. Do I need to write code to parse out the Request.Form("UserOptions") results, or is there a better way.
 
Yes, that's how you do it... if the user selects multiple, then the data is sent in a comma separated list. You should use split() to retrieve the values.

dim vals, valArray
vals = request.form("userOptions")
valArray = split(vals,",")

:)
paul
penny1.gif
penny1.gif
 
that will work fine if you have a multiple choice select box and you retrieve that control.
What if user have bunch of checkboxes?
 
Just_a_guy...I believe they are talking about checkboxes...but if not, go to this site I wrote up real quick to view how the checkboxes work and get the source code for how to control it. Pretty much the same as they are talking about here.

-Ovatvvon :-Q
 
No, we weren't talking about checkboxes, and I never even knew you could do checkboxes like radio buttons and get a comma separated list. SWEET!

Thanks, Ovatvvon! :)
penny1.gif
penny1.gif
 
heh, glad to be of service. Unusual that I am able to provide new information to you Link9! :p

Just out of curiousity then, what exactly where you talking about with the selection options above? You're naming select boxes with the same name to retrive from the next page? -Ovatvvon :-Q
 
It's just like a regular <select> (dropdown list), only this particular flavor doesn't actually dropdown... rather, it is a little window with selections available, and if a user holds <CTRL> when they make their selections, they are able to select more than one (hence the difference from the garden variety <select>).

Here's an example:
Code:
<select name=&quot;select&quot; size=&quot;5&quot; multiple>
  <option value=&quot;1&quot; selected>1</option>
  <option value=&quot;2&quot;>2</option>
  <option value=&quot;3&quot;>3</option>
  <option value=&quot;4&quot;>4</option>
  <option value=&quot;5&quot;>5</option>
  <option value=&quot;6&quot;>6</option>
  <option value=&quot;7&quot;>7</option>
  <option value=&quot;8&quot;>8</option>
  <option value=&quot;9&quot;>9</option>
  <option value=&quot;10&quot;>10</option>
</select>

and then you just grab the stuff just like you do with the comma separated checkbox list, as you described.

:)
paul
penny1.gif
penny1.gif
 
ah yes, I did know about that, just haven't had a need for it, so temp forgot about it. :)

Thanks. -Ovatvvon :-Q
 
I *think* that if you have two or more of the same names in the form, eg:

Code:
<input name=&quot;abc&quot;
<input name=&quot;abc&quot;

it'll give you a comma separated list as well. One of those things you find in debugging :)


(you can tell I haven't been here in a while, I'm using the TTML tags all over the place :) ) leo

------------
Leo Mendoza
lmendoza@students.depaul.edu
 
actually I'm using different method and was hoping to see something different that I know. I deal with a lot of database driven tools where users need to make a selection of control. Or imagine database driven survey where you have option buttons, checkboxes and textboxex loaded from db and all on the same page.
Very simple thing I use is form collection.
Say you have:
<input type=checkbox name=chk1 value=1>
<input type=checkbox name=chk2 value=2>
<input type=checkbox name=chk3 value=3>

<input type=radio name=what value=&quot;yes&quot;>
<input type=radio name=what value=&quot;no&quot;>

when form is submitted, you get elements of form collection like this:
for each objItem in request.form
if left(objItem,8)=&quot;checkbox&quot; then
selectedItem=Request.Form(objItem)
'store it or put into database or any process
elseif left(objItem,5)=&quot;radio&quot; then
selectedItem=Request.Form(objItem)
'store it or put into database or any process
end if
next

works nicely. place response.write in place of code withing for each-next and see all form elements and values submitted

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top