469,271 Members | 1,551 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.

getting drop down box value

Hi,

How to get the value from drop down menu into javascript function, I need the value not the selected option.

Here is the code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function disp_text()
  5.    {
  6.    var w = document.myform.mylist.selectedIndex;
  7.    var selected_text = document.myform.mylist.options[w].text;
  8.    alert(selected_text);
  9.    }
  10. </script>
  11.  
  12. <FORM NAME="myform">
  13. <SELECT NAME="mylist" onChange="disp_text()">
  14. <OPTION VALUE="m1">Cape Fear
  15. <OPTION VALUE="m2">The Good, the Bad and the Ugly
  16. <OPTION VALUE="m3">The Omen
  17. <OPTION VALUE="m4">The Godfather
  18. <OPTION VALUE="m5">Forrest Gump
  19. </SELECT>
  20. </FORM>
  21. </head>
  22. </html>

If the user selects an option for eg, if he selects "Cape Fear" then I will get the same thing in the javascript function, but what I need is "m1"., i.e. if he selects "The omen" I need "m3". How to do this. Please help me.

With regards
Mar 20 '08 #1
4 1742
ronverdonk
4,258 Expert 4TB
Try this
Expand|Select|Wrap|Line Numbers
  1. var selected_value = document.myform.mylist.options[w].value;
Ronald
Mar 20 '08 #2
acoder
16,027 Expert Mod 8TB
or even
Expand|Select|Wrap|Line Numbers
  1. var selected_value = document.myform.mylist.value;
Mar 20 '08 #3
Thank you for the reply
Mar 22 '08 #4
acoder
16,027 Expert Mod 8TB
You're welcome :)
Mar 22 '08 #5

Post your reply

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

Similar topics

1 post views Thread by Dan | last post: by
1 post views Thread by Ian Davies | last post: by
2 posts views Thread by Yoshitha | last post: by
5 posts views Thread by Vigneshwar Pilli via DotNetMonster.com | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.