469,271 Members | 1,586 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Retrieving values from select option

219 100+
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?

Expand|Select|Wrap|Line Numbers
  1. <select name="refresh_rate" id="refresh_rate" onChange="set_refresh_rate(this);return false;">
  2.     <option value="60">60 Seconds</option>
  3.         <option value="30">30 Seconds</option>
  4.         <option value="15">15 Seconds</option>
  5. </select>
  6.  
Jun 24 '08 #1
3 1789
DrBunchman
979 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1.  <select name="DropDown1"> 
  2.    <option value="A£Option 1">Option 1</Option>
  3.    <option value="B£Option 2">Option 2</Option>
  4. </select>
  5.  
  6. <%
  7. Dim sDropDown1, sValue, sText
  8. sDropDown1 = Request.Form("DropDown1")
  9. If InStr(sDropDown1, "£") > 0 Then
  10.      sValue = Split(sDropDown1, "£")(0)
  11.      sText= Split(sDropDown1, "£")(1)
  12. End If
  13. %>
  14.  
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
Jun 24 '08 #2
dmorand
219 100+
That's what I figured I'd have to do. Thanks Dr B!!!
Jun 24 '08 #3
DrBunchman
979 Expert 512MB
My pleasure....

Dr B
Jun 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Klaas Seelen | last post: by
15 posts views Thread by gunnar.sigurjonsson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.