Javascript examples for DOM HTML Element:Option
Option selected Property - Find out if the "banana" option in a drop-down list is selected or not:
<!DOCTYPE html> <html> <body> <form> Select your favorite fruit: <select> <option id="a">Apple</option> <option id="orange">Orange</option> <option id="pineapple" selected>Pineapple</option> // Pre-selected <option id="banana">Banana</option> </select>/* w w w .j a va 2 s . com*/ </form> <button onclick="myFunction()">Test</button> <script> function myFunction() { var v = document.getElementById("orange").selected; console.log(v); } </script> </body> </html>