Text Value of DropDown box

Discussion in 'ASP General' started by Bhaskar Reddy, Apr 19, 2006.

  1. Hi,

    I have a drop down as below.

    <select id="drp1">
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>


    I need the text value of the drop down box.

    Request.form("drp1").value is giving 1 , but I need the value "One". How can
    I do this.

    Please Help.

    Thanks
     
    Bhaskar Reddy, Apr 19, 2006
    #1
    1. Advertising

  2. Bhaskar Reddy

    Mike Brind Guest

    Bhaskar Reddy wrote:
    > Hi,
    >
    > I have a drop down as below.
    >
    > <select id="drp1">
    > <option value="1">One</option>
    > <option value="2">Two</option>
    > </select>
    >
    >
    > I need the text value of the drop down box.
    >
    > Request.form("drp1").value is giving 1 , but I need the value "One". How can
    > I do this.
    >
    > Please Help.
    >
    > Thanks


    You could do this:
    <select id="drp1">
    <option value="One">One</option>
    <option value="Two">Two</option>
    </select>

    Or this:
    <select id="drp1">
    <option>One</option>
    <option>Two</option>
    </select>

    --
    Mike Brind
     
    Mike Brind, Apr 19, 2006
    #2
    1. Advertising

  3. Bhaskar Reddy wrote:
    > Hi,
    >
    > I have a drop down as below.
    >
    > <select id="drp1">
    > <option value="1">One</option>
    > <option value="2">Two</option>
    > </select>
    >
    >
    > I need the text value of the drop down box.
    >
    > Request.form("drp1").value is giving 1 , but I need the value "One".
    > How can I do this.
    >
    > Please Help.
    >

    As you have seen, only the value property gets passed via the Request
    object.

    This is not the first time I've seen this question, and frankly, I'm a
    little puzzled by it: aren't you in control of the source of those
    value-text pairs? Why can't you simply retrieve the text from the data
    source based on the passed value? I suppose you could be using some
    client-side data source for the option list ... ?

    Anyways, you have a few options:

    Make the text be part of the value when populating the options:
    <option value="1 - One">One
    allowing you to use Split() to retrieve both values from
    request.form("drp1")

    Use client-side code to populate a hidden field when the form is submitted
    (see a client-side group such as .scripting.jscript for this).

    Store the value-text pairs in an xml document on the web server, either in a
    file or in a session variable

    --
    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], Apr 19, 2006
    #3
  4. Bob Barrows [MVP] wrote:
    > This is not the first time I've seen this question, and
    > frankly, I'm a little puzzled by it: aren't you in control
    > of the source of those value-text pairs? Why can't you
    > simply retrieve the text from the data source based on the
    > passed value?


    Or simply: What is the point of a value that differs from the text if you
    want the text?



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Apr 19, 2006
    #4
    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. Mike
    Replies:
    1
    Views:
    824
  2. Gnarlodious
    Replies:
    4
    Views:
    17,640
    elizas
    May 5, 2010
  3. TJHerman

    Populate text box with value from dropdown list

    TJHerman, Jun 14, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    191
    TJHerman
    Jun 14, 2006
  4. jnag
    Replies:
    2
    Views:
    307
    Nick Fletcher
    Feb 27, 2008
  5. Lewis
    Replies:
    1
    Views:
    210
Loading...

Share This Page