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

Capture Value from Drop Down Menu 1

Status
Not open for further replies.

Airpan

Technical User
Jun 14, 2005
172
0
0
US
I have a form that utilizes drop downs. I would like to be able to pull those values from the form and have it update the database. Is this the correct syntax to do so?
Code:
frmyear=Request.Form("year"(1,2))



~E
 
If it's a non multiple <select> box, then only the selected item gets passed on form submission.

If you have more than one dropdown with the same name, the information gets passed in an array of that name.

In what you have above, you are trying to reference a 2 dimensional array, that won't happen.

if you have <select name="year"> ...... in your html, you can access this by doing this:

Code:
frmyear=Request.Form("year")

if you have more than 1 <select name="year"> ..., you can access what you want by choosing an index like this:

Code:
frmyear=Request.Form("year")(1)

Here is a quick writeup I did:
Code:
<%@LANGUAGE="VBScript"%>
<%
   dim cheese, rat
   rat = Request.Form("rat")
   if rat = 1 then
      cheese = Request.Form("year")[!](2)[/!]
      Response.Write cheese
   end if
   
%>
<html>
<body>
<form method="post">
<select name="year">
<option value="2004">2004</option>
</select>
<select name="year">
<option value="2002">2002</option>
</select>
<select name="year">
<option value="2001">2001</option>
</select>
<input type="hidden" name="rat" value="1" />
<input type="submit" />
</form>
</body>
</html>

You can test this by changing the highlighted number to other values to see what happens.




[monkey][snake] <.
 
Thanks Monksnake. Will go test it and see what happens. Thanks for the help - again. :eek:)

~E
 
monksnake,
Thanks for the code, I tested it. That is pretty handy indeed. I used the wrong verbage to explain what I am trying to do though. I have a list which allows multiple selections to be chosen. I need to be able to capture all of them that the user selects. I tried searching for examples of the code online, but did not find it in regular ASP , but I did see lots of examples of ASP.NET. My old textbook didn't really give any examples. Is the same as the other types? I am getting an error when I try to run the page, but figured I would check my syntax for those first, and then if I get the error again will post it. Thanks.

~E
 
Here is the code just in case I am not being clear:
Code:
<select name="opt" size="3" multiple>
  <option value="AC">AC</option>
  <option value="Power steering">Power steering</option>
  <option value="Cruise Control">Cruise Control</option>
  <option value="Radio">Radio</option>
  <option value="Bench Seat">Bench Seat</option>
  <option value="Lift Gate">Lift Gate</option>
</select>

~E
 
Ahh I see a multiple select. I can think of a way off hand to do this, but I'll first test to see if there's an easier way.

[monkey][snake] <.
 
I modified the code that I wrote yesterday:

Code:
<%@LANGUAGE="VBScript"%>
<%
   dim cheese, rat
   rat = Request.Form("rat")
   if rat = 1 then
      cheese = Split(Request.Form("year"),",")
      for each item in cheese
         Response.Write item & "<br />"
      next 
   end if
   
%>
<html>
<body>
<form method="post">
<select name="year" size="3" multiple>
  <option value="AC">AC</option>
  <option value="Power steering">Power steering</option>
  <option value="Cruise Control">Cruise Control</option>
  <option value="Radio">Radio</option>
  <option value="Bench Seat">Bench Seat</option>
  <option value="Lift Gate">Lift Gate</option>
</select>
<input type="hidden" value="1" name="rat" />
<input type="submit" />
</form>
</body>
</html>


I'm not sure exactly how you want to insert these values in a database, but this code shows you how to extract each value selected from the dropdown.


[monkey][snake] <.
 
Awesome monksnake, I will play around with it. It is pointing me in the right direction and usually that is all I need. Thanks again.

~E
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top