GETTING THE TEXT FROM A DROP-DOWN BOX

john rob

Total Post:108

Points:756
Posted by  john rob
 1276  View(s)
Ratings:
Rate this:

Hi MindStickians!

This gets the value of whatever is selected in my dropdown menu.

document.getElementById('newSkill').value

For those not sure, here's the HTML for a drop down box.

<select name="newSkill" id="newSkill">
    <option value="1">A skill</option>
    <option value="2">Another skill</option>
    <option value="3">Yet another skill</option>
</select>

Thanks in advance

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Getting the text from a drop-down box

    Hi John!

    For getting the text from a drop-down box as below

    var skillsSelect = document.getElementById("newSkill");
    var selectedText = skillsSelect.options[skillsSelect.selectedIndex].text;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!