Drop-Down Display vs. Value

B

bryan.com

There must be a way.
I'm making a selection from a drop-down list that had an ID number as
the value and displays a text field. After submitting the data to the
database I am sending an email and would like to include the value
displayed in the DD box, not the hidden value. How so I reference that
displayed value?
<select name="select">
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
</select>

I want to use the number for the database but display the words in the
confirmation email. Is thsi possible without making another roundtrip
to the database?
 
M

McKirahan

There must be a way.
I'm making a selection from a drop-down list that had an ID number as
the value and displays a text field. After submitting the data to the
database I am sending an email and would like to include the value
displayed in the DD box, not the hidden value. How so I reference that
displayed value?
<select name="select">
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
</select>

I want to use the number for the database but display the words in the
confirmation email. Is thsi possible without making another roundtrip
to the database?


document.forms[0].select.options[document.forms[0].select.selectedIndex].tex
t;
 
B

bryan.com

I appreciate the reply but I just get an error. The DD list I'm using
is called selHomeID.
var HomeAddress =
document.forms[0].selHomeID.options[document.forms[0].selHomeID.selectedIndex].text;

Can you explain this a little and how I should be using it.
 
M

McKirahan

I appreciate the reply but I just get an error. The DD list I'm using
is called selHomeID.
var HomeAddress =
document.forms[0].selHomeID.options[document.forms[0].selHomeID.selectedInde
x].text;

Can you explain this a little and how I should be using it.

What error? Try this "as-is".

<html>
<head>
<title>selHomeID.htm</title>
<script type="text/javascript">
function HomeID() {
var form = document.form1;
var pick = form.selHomeID.selectedIndex;
var HomeAddress = form.selHomeID.options[pick].text;
alert(HomeAddress);
}
</script>
</head>
<body>
<form name="form1">
<select name="selHomeID">
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
</select>
<input type="button" value="HomeID" onclick="HomeID()">
</form>
</body>
</html>
 
B

Bob Barrows [MVP]

There must be a way.
I'm making a selection from a drop-down list that had an ID number as
the value and displays a text field. After submitting the data to the
database I am sending an email and would like to include the value
displayed in the DD box, not the hidden value. How so I reference that
displayed value?
<select name="select">
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
</select>

I want to use the number for the database but display the words in the
confirmation email. Is thsi possible without making another roundtrip
to the database?

I assume you are talking about doing this in server-side code. If so, there
is really no way to directly read the display value from the Request: only
the values are sent via Request which you have already discovered.

Yes, you could make another trip to the database to retrieve the value, but
that really is not necessary. There are several options:

1. Use client-side code to store the text of the selected option in a hidden
field.
2. You could store the value-text list used to create the options in a
session variable, perhaps using an xml document, and then simply look up the
text using the value received from Request via an XPath query usnig
selectSingleNode.
3. Or, if you could, when you originally build the options, disconnect the
recordset from the database, use its Save method to save it as xml and
either save it to a file or to a session variable, thenwhen processing the
request, open a new recordset using the xml-persisted recordset as the
source.

Think about it and decide which route you wish to take. If you decide on the
first option and need help implementing it, you should move this
conversation to a client-side scripting group such as
microsoft.public.scripting.jscript. Otherwise, get back to us for help with
either of the other two options.

Bob Barrows
 
T

Tim Slattery

There must be a way.
I'm making a selection from a drop-down list that had an ID number as
the value and displays a text field. After submitting the data to the
database I am sending an email and would like to include the value
displayed in the DD box, not the hidden value. How so I reference that
displayed value?
<select name="select">
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
</select>

I want to use the number for the database but display the words in the
confirmation email. Is thsi possible without making another roundtrip
to the database?

You could make the "values" compound, something like this:

<option value="1;blue">Blue</option>
<option value="2;red">Red</option>
<option value="3;green">Green</option>

Then use the "split" function to break the returned value into its
component parts. Now you have both the number and the string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top