473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Display description in dropdown list but store another value in variable

63
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 4622
DrBunchman
979 Expert 512MB
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 Expert 256MB
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 Expert 2GB
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
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 Expert 2GB
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 Expert 512MB
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
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 Expert 512MB
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
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...
2
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...
2
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...
5
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...
1
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...
6
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...
1
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...
8
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...
1
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.