Javascript examples for DOM HTML Element:Option
The form property returns the form that contains an option.
A reference to the form element containing the option. If the option is not in a form, null is returned
The following code shows how to return the id of the form containing the <option> element with id="a":
<!DOCTYPE html> <html> <body> <form id="myForm"> Select your favorite fruit: <select> <option id="a">Apple</option> <option id="orange">Orange</option> <option id="pineapple">Pineapple</option> <option id="banana">Banana</option> </select>/*from ww w .j a va2s .c o m*/ </form> <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("a").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>