<!DOCTYPE html> <html> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <select id="mySelect"> <option>football</option> <option>Basketball</option> <option>Hockey</option> <option>Swiming</option> </select> <p> Click the button to select the option element with index "2". </p> <button onclick="myFunction()"> click me </button> <script> function myFunction() { document.getElementById( "mySelect").selectedIndex = "2"; } </script> </body> </html> |