Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
HTML DOM Select form Property
The HTML DOM select form property returns a reference to the form element that contains the dropdown list. This read-only property is useful for identifying which form a select element belongs to, especially in documents with multiple forms.
Syntax
Following is the syntax for the select form property −
selectElement.form
Return Value
The property returns a reference to the form element that contains the select element. If the select element is not within a form, it returns null.
Example − Basic Form Reference
Following example demonstrates how to get the form reference from a select element −
Select Form Property Select Form Property Demo
The output displays the form ID and name when the button is clicked −
Form ID: courseForm Form Name: courses
Example − Multiple Forms
Following example shows how to distinguish between multiple forms using the form property −
Multiple Forms Example Multiple Forms with Select Elements
Each button identifies which form contains the respective select element −
Select element 'country' belongs to form: personalForm Select element 'degree' belongs to form: educationForm
Example − Select Outside Form
Following example demonstrates what happens when a select element is not within a form −
Select Outside Form Select Element Outside Form
Select element outside any form:
The select element outside the form returns null, while the one inside returns the form reference −
Select 'insideSelect' is inside form: testForm Select 'outsideSelect' is NOT inside any form (returns null)
Key Points
The
formproperty is read-only and cannot be modified.It returns
nullif the select element is not contained within a form.This property is inherited from the
HTMLSelectElementinterface.Useful for form validation and determining the context of select elements in complex documents.
Browser Compatibility
The select form property is supported in all major browsers including Chrome, Firefox, Safari, Edge, and Internet Explorer. It is part of the standard DOM specification and has been available since early browser versions.
Conclusion
The HTML DOM select form property provides a convenient way to access the parent form of a select element. It returns the form reference when the select is inside a form, or null when it's not, making it useful for form validation and dynamic form handling.
