JavaScript: How to Get Selected Item in Dropdown Select List

***If this post helped you, please support this blog by clicking one of the links on this page. Thanks :) ***

JavaScript can be used to retrieve what the currently selected item is in a dropdown select list. Consider the following example, which shows how to get both the text and value of the selected item in a dropdown select list:

The preceding example uses the selectedIndex property of the dropdown box to return the index of the selected item, with the first item in the list being 0, the second being 1 and so forth. Once the selectedIndex is retrieved, the select box values are referenced as an array. The element retrieved is the element existing in the selectedIndex position.

Related Articles:
JavaScript selectedIndex property
Accessing Form Elements with JavaScript

34 Responses to “JavaScript: How to Get Selected Item in Dropdown Select List”

  1. Neal Says:

    I’m able to get both of those methods to work in Firefox 2.0 however in IE7 it return nothing?

    Is there a special way this needs to be done for IE7?

  2. Joieta Says:

    It helped me 2 solve a critical problem
    Thanks a lot 4 this……………

  3. Gep Says:

    Thank you so much. I found it really useful! )

  4. vision Says:

    Good. It’s helpful to me. Thanks!

  5. raj Says:

    i want selected item label not its value…

  6. kiran Says:

    good site it was very usefull to me at the right time .

  7. Percy Says:

    Thnks it really worked for me.

  8. eanirudh Says:

    can u tell me how to get the text

  9. Självständigt Skåne Says:

    Thanks! This really helped me. I was almost going to traverse the DOM structure until i found this…

  10. Deepa Says:

    This Post really helped me. Thank you.

  11. neel_1708 Says:

    hi can you tell me how to display select box using DOM and getting selected value from that select box in that function itself

  12. Jason R Says:

    I should note that this does NOT work in IE7.

    where was the Testing/QA on this, Joey??

  13. Yash Says:

    thnks a lot.

  14. Jeff Says:

    Guys,
    It looks like you leave me no choice …
    I just have to bookmark you :)

    Good stuff — thank you.

    Jeff

  15. sunny Says:

    Thank you very much. It is useful.

  16. Jade Says:

    gracias.

  17. Sashi Says:

    Thanks, it worked exactly.

  18. elsint Says:

    agree, doesn’t work on IE7

  19. elsint Says:

    this works fine on ie[<=7]:

    document.write(document.getElementById('colorsselect').options[dropdownIndex].text);

  20. indar Says:

    this Soution is too easy to understand.
    it really helped me a lot.
    Keep writing such solutons…. man.

  21. Faffe Says:

    Thankss.. really need this!!

  22. Moe Says:

    Hi,

    I am working in crm and I am trying to check a checkbox depending on the value selected in a drop down. For example if option 1 is chosen from the drop down then the check box must be checked. I am puuting my code in the onChange event of the drop down in crm but it does not seem to work.

    Any help will be highly appreciated.

  23. Joey Says:

    Do you have sample code for what you’re trying to do?

  24. R. Luiten Says:

    For the people who want to use this solution, please read this:
    This solution does not work in Internet Explorer 7, which is still a great part of the possible visitors of your website.

    Please don’t use this solution!

  25. John Says:

    Not working in IE from what I can tell. Keep that in mind. You should write that somewhere.

  26. Joey Says:

    This absolutely works in IE7. Note that this gets the dropdown’s selected option value, not the displayed text.

  27. Joey Says:

    Actually, it works fine in IE7. Any evidence to back up that it doesn’t?

  28. Paul Says:

    Works fine in my IE8, and in the IE9 Platform Preview.

    Just how do you get the displayed text, not the ‘value’.

  29. Joey Says:

    Paul, I’ve updated the example to show how to get the text as well.

  30. Ram Says:

    simply good stuff . thanks for all.

  31. mukesh Says:

    It’s working thanks

  32. Khang Says:

    I Love You!!!

  33. melissa Says:

    Thank you, this is very helpful :)

  34. Sachin Vats Says:

    i m a BCA student n i jst searched “how to get selected value in combo box”
    n this is my 11th site after searching the code n i found it is really very gud site for everyone. it has very very nice stuff (error free). n i will suggest to all my near n dear.

Leave a Reply