The HTML DOM select form property returns the reference of the form that contain the drop-down list.
Syntax
Following is the syntax −
object.form
Example
Let us see an example of HTML DOM select form property −
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
background-color:#363946;
color:#fff;
}
form{
margin:2.5rem auto;
border:1px solid #fff;
padding:2rem;
}
.drop-down{
display:block;
width:35%;
border:2px solid #fff;
font-weight:bold;
padding:2px;
margin:1rem auto;
outline:none;
}
button{
background-color:#db133a;
border:none;
cursor:pointer;
padding:8px 16px;
color:#fff;
border-radius:5px;
font-size:1.05rem;
outline:none;
}
.show{
font-weight:bold;
font-size:1.4rem;
}
</style>
</head>
<body>
<h1>form Property Demo</h1>
<form id="Form 1">
<legend style="font-weight:bold;">Form 1</legend>
<p>Hi, Select your favourite subject:</p>
<select class='drop-down' name="Drop Down List">
<option>Physics</option>
<option>Maths</option>
<option>Chemistry</option>
<option>English</option>
<option>Economics</option>
<option>Hindi</option>
<option>Biology</option>
</select>
</form>
<button onclick="identify()">Identify form of drop-down</button>
<p class="show"></p>
<script>
function identify() {
var formId = document.querySelector(".drop-down").form.id;
document.querySelector(".show").innerHTML = "Hi! I'm from " + formId;
}
</script>
</body>
</html>Output
This will produce the following output −

Click on “identify form of drop-down” button to identify the form that reference the drop-down list −
