Option form Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


The form property returns the form that contains an option.

Return Value

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":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form id="myForm">
Select your favorite fruit:
  <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*/

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("a").form.id;
    document.getElementById("demo").innerHTML = x;


Related Tutorials