Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> Select your favorite car: <br> <select id="mySelect" size="4"> <option label="Volvo">Volvo (Latin for "I roll")</option> <option label="Saab">Saab (Swedish Aeroplane AB)</option> <option label="Mercedes">Mercedes (Mercedes-Benz)</option> <option label="Audi">Audi (Auto Union Deutschland Ingolstadt)</option> </select> <p>Click the button to return the label value of the selected car.</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].label); } </script> </body> </html>