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 fruit: <select id="mySelect"> <option value="apple">Apple</option> <option value="orange">Orange</option> <option value="pineapple">Pineapple</option> <option value="banana">Banana</option> </select> <p>Click the button to return the value of the selected fruit.</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].value); } </script> </body> </html>