Drop-Down Display vs. Value

Discussion in 'ASP General' started by bryan.com@gmail.com, Mar 9, 2006.

  1. Guest

    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?
     
    , Mar 9, 2006
    #1
    1. Advertising

  2. McKirahan Guest

    <> wrote in message
    news:...
    > 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;
     
    McKirahan, Mar 9, 2006
    #2
    1. Advertising

  3. Guest

    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.
     
    , Mar 9, 2006
    #3
  4. McKirahan Guest

    <> wrote in message
    news:...
    > 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>
     
    McKirahan, Mar 9, 2006
    #4
  5. wrote:
    > 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
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Mar 9, 2006
    #5
  6. Tim Slattery Guest

    "" <> wrote:

    >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.

    --
    Tim Slattery
    MS MVP(DTS)
     
    Tim Slattery, Mar 9, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    803
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,050
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    523
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    302
  5. Replies:
    3
    Views:
    314
Loading...

Share This Page