Option formProperty
Option Object
Definition and Usage
The form property returns a reference to the form that contains the option.
This property returns the form object.
Syntax
optionObject.form
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the form property
Example
Example
This example returns the form ID of the selected option in the drop-down list:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("mySelect").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Choose your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Show the form ID</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("mySelect").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Choose your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Show the form ID</button>
</body>
</html>
Try it Yourself »
Option Object Other Extensions