Retrieving values from select option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmorand
    New Member
    • Sep 2007
    • 219

    Retrieving values from select option

    How do I go about retrieving the inner text from select options with asp? I am using the values to do some calculations, but I want to retrieve the inner text of the option field for display purposes, how would I go about doing this?

    [code=html]
    <select name="refresh_r ate" id="refresh_rat e" onChange="set_r efresh_rate(thi s);return false;">
    <option value="60">60 Seconds</option>
    <option value="30">30 Seconds</option>
    <option value="15">15 Seconds</option>
    </select>
    [/code]
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Unfortunately, you can't.

    If you want to retrieve the option text then you'll need to include it in the value field separated by some sort of delimiter and then split the value back into two when you request it. Here's an example:
    Code:
     <select name="DropDown1"> 
       <option value="A£Option 1">Option 1</Option>
       <option value="B£Option 2">Option 2</Option>
    </select>
     
    <%
    Dim sDropDown1, sValue, sText
    sDropDown1 = Request.Form("DropDown1")
    If InStr(sDropDown1, "£") > 0 Then
    	 sValue = Split(sDropDown1, "£")(0)
    	 sText= Split(sDropDown1, "£")(1)
    End If
    %>
    The split function literally splits the string up at the selected point (in this case when it finds a £ sign) and assigns it to our two variables.

    Let me know if this helps,

    Dr B

    Comment

    • dmorand
      New Member
      • Sep 2007
      • 219

      #3
      That's what I figured I'd have to do. Thanks Dr B!!!

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        My pleasure....

        Dr B

        Comment

        Working...