The HTMLSelectElement.form
read-only property returns a HTMLFormElement
representing the form that this element is associated with. If the element is not associated with a <form>
element, then it returns null
.
The HTMLSelectElement.form
read-only property returns a HTMLFormElement
representing the form that this element is associated with. If the element is not associated with a <form>
element, then it returns null
.
html
<form id="pet-form"> <label for="pet-select">Choose a pet</label> <select name="pets" id="pet-select"> <option value="dog">Dog</option> <option value="cat">Cat</option> <option value="parrot">Parrot</option> </select> <button type="submit">Submit</button> </form> <label for="lunch-select">Choose your lunch</label> <select name="lunch" id="lunch-select"> <option value="salad">Salad</option> <option value="sandwich">Sandwich</option> </select> <script> const petSelect = document.getElementById("pet-select"); const petForm = petSelect.form; // <form id="pet-form"> const lunchSelect = document.getElementById("lunch-select"); const lunchForm = lunchSelect.form; // null </script>
Specification |
---|
HTML Standard # dom-fae-form-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
form |
1 | 12 | 1 | 5.5 | ≤12.1 | 3 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/form