473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display description in dropdown list but store another value in variable

63 New Member
Is there a way to set up a dropdown list and have the description field be displayed as a selection for the user and also be displayed in the input field after the user selects it, but have the value be stored in the variable? In the example below, the user would see Report A, but Rpt0001 would be stored in variable strReportName. Is it possible to do this?

Expand|Select|Wrap|Line Numbers
  1. <select name="ReportName" id="ReportName">  
  2. <option><%=strReportName%></option>  
  3. <option value="Rpt0001">Report A</option>
  4. <option value="Rep0002">Report B</option>
  5. <option value="Rep0003">Report C</option>
  6. <option value="Rep0004">Report D</option>
  7. </select>
Sep 19 '08 #1
8 4632
DrBunchman
979 Recognized Expert Contributor
Hi rmurgia,

I'm not 100% clear on what you are trying to do. If you want to assign the value of the drop down to the variable strReportName then you can do so after your form has been submitted with

Expand|Select|Wrap|Line Numbers
  1. <%
  2. strReportName = Request("ReportName")
  3. %>
If that doesn't help could you try to explain the problem again?

Thanks,

Dr B
Sep 19 '08 #2
jeffstl
432 Recognized Expert Contributor
You will not store the value of the selected option in strReportName based on the code you posted no.

You would need to catch the value on the request.form side after the form is submitted to a .asp as a post.

Similar to how Dr. B put it

Expand|Select|Wrap|Line Numbers
  1. strReportName = request.form("ReportName")
  2.  
So yes it is possible to answer your question. Is this what you were asking?

What you posted would create a drop down with the top choice a blank one because you have that choice set to strReportName which at the time of running I assume has nothing in it...therefore blank option in your drop down. So probably not what your going for.
Sep 19 '08 #3
jhardman
3,406 Recognized Expert Specialist
I guess I'm also not sure what he's asking, but it looks to me like the answer is a simple "yes". You know that if you just right this:
Expand|Select|Wrap|Line Numbers
  1. <option>report a</option>
then you see "report a" in the drop down and this value is passed when the form is submitted. Many people code like this. On the other hand, it would be better to code like this:
Expand|Select|Wrap|Line Numbers
  1. <option value="rpt_a">report a</option>
so that the user sees "report a" but the text "rpt_a" is sent to the form handler. It sure sounds to me that this is all he's asking - and the answer is "yes".

Jared
Sep 22 '08 #4
rmurgia
63 New Member
Hi rmurgia,

I'm not 100% clear on what you are trying to do. If you want to assign the value of the drop down to the variable strReportName then you can do so after your form has been submitted with

Expand|Select|Wrap|Line Numbers
  1. <%
  2. strReportName = Request("ReportName")
  3. %>
If that doesn't help could you try to explain the problem again?

Thanks,

Dr B

Dr B,

Thanks for the reply. I guess I was not clear enough in my example. What I was trying to do was to show a dropdown which displays some information to the user, but stores different information in the variable. The current situation is where the user sees and employee # and employee name on the dropdown:

Emp # Emp Name
001 John Smith
002 Paul Jones

After the name Paul Jones is selected, I wanted to display Paul Jones in the field, but store 002 in the variable. Currently after the selection is made, the user sees 002 in the field and the name is no longer available:

Emp: 001

It seems that the only way to accomplish this would be to create another variable to hold the name and then display it as a non-updatable field after the selection is made:

Emp #: 001
Emp Name: Paul Jones
Sep 23 '08 #5
jhardman
3,406 Recognized Expert Specialist
I think I've got you. Once the form is submitted, the number is submitted rather than the name, so for example on a confirmation page the user sees a number which means nothing outside of the correct context. Is this right? If so, then let me ask you how you have the data stored (are the employee name and numbers coming from a db?) - the solution depends on where the data comes from.

A long time ago I made a non-compliant javascript function that added an unsupported attribute to the options, then I got the extra attributes value to pass to a hidden text field for similar reasons to yours. Although I got this to work in IE5, there are better solutions around today. Anyway, answer my question, and I'll tell you what I got.

Jared
Sep 24 '08 #6
DrBunchman
979 Recognized Expert Contributor
You could put the description alongside the value in the value attribute of your options and separate them with a delimiter. Then parse that requested value after the form is submitted. Take a look at this example:

Expand|Select|Wrap|Line Numbers
  1. <form name='f1'>
  2. <select name='s1'>
  3.     <option value='001£John Smith'>John Smith</option>
  4.     <option value='002£Paul Jones>Paul Jones</option>
  5. </select>
  6. </form>
  7.  
  8. <%
  9. Dim s1, strValue, strDescription
  10. s1 = Request("s1")
  11. If InStr(s1, "£") > 0 Then
  12.     strValue = Split(s1, "£")(0)
  13.     strDescription= Split(s1, "£")(1)
  14. End If
  15. Response.Write "Value is " & strValue
  16. Response.Write "<br />"
  17. Response.Write "Description is " & strDescription
  18. %>
Does this make sense? Let me know how you get on.

Dr B
Sep 24 '08 #7
rmurgia
63 New Member
You could put the description alongside the value in the value attribute of your options and separate them with a delimiter. Then parse that requested value after the form is submitted. Take a look at this example:

Expand|Select|Wrap|Line Numbers
  1. <form name='f1'>
  2. <select name='s1'>
  3.     <option value='001£John Smith'>John Smith</option>
  4.     <option value='002£Paul Jones>Paul Jones</option>
  5. </select>
  6. </form>
  7.  
  8. <%
  9. Dim s1, strValue, strDescription
  10. s1 = Request("s1")
  11. If InStr(s1, "£") > 0 Then
  12.     strValue = Split(s1, "£")(0)
  13.     strDescription= Split(s1, "£")(1)
  14. End If
  15. Response.Write "Value is " & strValue
  16. Response.Write "<br />"
  17. Response.Write "Description is " & strDescription
  18. %>
Does this make sense? Let me know how you get on.

Dr B
Dr B,

You have hit on exactly what I was describing. I wanted to display a meaningful name to the user, but store the key (in this case the employee Id) in the field. In the process of wanting a fast solution, I made another call to the database to retrieve the employee name using the employee Id. However, I like your solution better, since I can avoid the second call to the database.

Thanks for the help.
Sep 25 '08 #8
DrBunchman
979 Recognized Expert Contributor
No problem, glad to help.

Dr B
Sep 25 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3460
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I want to be able to select an item on the dropdown list based on the value of the javascript variable. Let's say this is my list and my variable: <select id='popup'>
2
1352
by: Peter | last post by:
I want to display the dropdown list in the combo box when the combo box gets focus (when user tabs to this control), how do I do this? (I am sure this has been answered before but I can't find the answer) Thanks Peter
2
4015
by: Jim via DotNetMonster.com | last post by:
Hi, I'm passing a variable to another page through a querystring. I then want to use that variable to retrieve records from a database to poulate a dropdownlist. I can read the variable from the querystring but I'm not sure how to pass that value. I get the error that IntCourseID is not declared in: <asp:DropDownList id="fLessonID" runat="server" DataValueField="LessonID" DataSource="<%# GetLessons(IntCourseID) %>"
5
11891
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
1
3865
by: Nitin Nikam | last post by:
Hello, I m developing application of link directory using VS-2005. In this application i have a dropdownlist. In dropdownlist i want to display categories, sub-categories, sub-sub-categories upto any level (for eg. country--state--district--city--village etc.) The dropdownlist will look like Arts --camera --photography
6
5847
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList ID="FldType_add" Runat="server" DataSource='< %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" /> Oce the page is loaded all the values are added to the dropdown list. But when I thought of getting the selected value from the...
1
1015
by: narasima | last post by:
Hi All, I am Narasimha. I want to be disply the dropdown list ,list box,check box in gridview control.and when your select in dropdown list option 2 two records are update when ever you click on submitt button.and when ever select the checkbox select items view in gridview control.pls help me. Thanks&regards, Narasimha
8
15288
by: stekk | last post by:
Question: How do I display/echo the values in page the selected values from drop down lists in page 2? I think this is the line that I have to add some code to make the values SELECTED. Any help is appreciated. echo "<option value=\"$name\">$name</option> \n" ; page1.php <? echo "<form name=sel>\n"; echo "VENDOR : <font id=vendor><select>\n"; echo "<option value='0'>============</option> \n" ; echo...
1
2420
by: Ahmad Nawaz | last post by:
I have a dropdown list which have some elements. I want to get all the elements of the dropdown list into a variable of type array. Any Idea???
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.