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!

Drop down Menus.

Status
Not open for further replies.

esaragosti

Programmer
Jun 15, 2007
5
CA
Hi there,
I have a drop down menu on one of my asp pages. I populate it dynamically putting the PK in the value, but putting the name of the department in the field so that the user can click on it.

I still need the PK to be there, but I now need the department as well so that I can send out an e-mail through this asp form.

The question is, is there a way to pull both pieces of information, or do I need to open a second database connection to check the deptartments name with it's Primary Key?

Thanks
Eric
 
Hi Eric,

Let me try and make sure that I understand what you want to do.

You a dept table that contains deptid and deptname.

You want to store deptid in the main table. However, you also want to pick up the information you inserted (deptid) and deptname from dept table and send them via email.

Did I get it right?

I can help with this but I want to make sure that I understand what you want.
 
Hey there,
When I create a drop-down list, there's the value that you give each row, in this case it's the PK for my table. You can also give the drop-down list a value that the user sees, which is not the same.

I already use the first value to know which department the user wants, but I'm hoping to use the second part of the table to use in an e-mail.

Here is an example of what the drop-down list would look like:
<SELECT NAME=agency style="font-size:8pt;">
<OPTION VALUE=2>BEL AGE
<OPTION VALUE=3>FCJA
<OPTION VALUE=2>CSQ

If in the asp I type request.form("agency") it will return 2,3, or 4. Now I want to pull the names Bel Age, FCJA, or CSQ. And I don't want to hardcode it, since the actual list is a hundred records long, and quite dynamic.

Thank you
Eric
 
In that case, you have to put that data into a hidden (textbox) control where the value is updated either from the onchange event of select-one element (slightly disadvantaged when the first option is used thereby onchange is never trigged) or use onsubmit to update the value. The mechanism is by large a client-side affair (so it is possible you could be advosed to ask in other forum like javascript forum).

The basic is this.
[1] Add a hidden within the form.
[tt] <input type="hidden" name="x" />[/tt]
[2] Add a onsubmit handler to the form. (I add the update inline. In case you've an elaborated handler, add essentially similar line to it.)
[tt] <form name="formname" action="etc" method="post" onsubmit="[blue]this.x.value=this.agency.options['this.agency.selectedIndex'].text;[/blue]">[/tt]
[3] You then read it server-side with.
[tt] p=request.form("x")
q=request.form("agency")[/tt]
and you will get back (p,q) pair like ("BEL AGE",2), or ("FCJA",3) etc etc.
 
Another option would be to store both values in the value of the option, and delimit them so you can later split it:
Code:
...
<option value="s:Bel Age">Bel Age</option>
...

This way on your enxt page you can retrieve the information like so:
Code:
Dim agency
If Len(Request.Form("agency")) > 0 Then
   agency = Split(Request.Form("agency"),":")
End If

An additional error check could be done using UBound to ensure you did receive two values.

-T

Best MS KB Ever:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top