Javascript Reference - HTML DOM Select form Property








The form property gets the form that contains the drop-down list.

Browser Support

form Yes Yes Yes Yes Yes

Syntax

var v = selectObject.form 

Return Value

A reference to the form element containing the drop-down list. If the drop-down list is not in a form, null is returned.





Example

The following code shows how to get the id of the form containing the drop-down list.


<!DOCTYPE html>
<html>
<body>
<!--from  ww  w.ja  va  2s .c om-->
<form id="myForm">
Select your favorite fruit:
<select id="mySelect">
  <option>A</option>
  <option>B</option>
  <option>C</option>
  <option>D</option>
</select>
</form>
<button type="button" onclick="myFunction()">test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("mySelect").form.id;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: