HTMLSelectElement.form

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 of a <form> element, then it returns null.

Syntax

Edit

JavaScript
aForm = aSelectElement.form.selectname; 

Example

HTML

JavaScript
<form action="http://www.google.com/search" method="get">
 <label>Google: <input type="search" name="q"></label> <input type="submit" value="Search...">
</form>

Javascript

A property available on all form elements, "type" returns the type of the calling form element. For SELECT, the two possible values are "select-one" or "select-multiple", depending on the type of selection list. The below code gives all SELECT elements in a particular form a CSS class of "selectclass":

JavaScript
<script type="text/javascript">
<code class="jscript keyword">var</code> <code class="jscript plain">form_element = document.getElementById(</code><code class="jscript string">'subscribe_form'</code><code class="jscript plain">);</code>
<code class="jscript keyword">var</code> <code class="jscript plain">vist = from_element.style;</code>
<code class="jscript keyword">if</code> <code class="jscript plain">(vist.display==</code><code class="jscript string">''</code> <code class="jscript plain">|| vist.display==</code><code class="jscript string">'none'</code><code class="jscript plain">)</code>
<code class="jscript plain">{</code>
<code class="jscript spaces"</code><code class="jscript plain">vist.display = </code><code class="jscript string">'block'</code><code class="jscript plain">;</code>
<code class="jscript plain">}</code>
<code class="jscript keyword">else</code>
<code class="jscript plain">{</code>
<code class="jscript spaces"</code><code class="jscript plain">vist.display = </code><code class="jscript string">'none';</code>
<code class="jscript plain">}</code>
</script>

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'HTMLSelectElement' in that specification.
Living Standard No change since the latest snapshot, HTML5.
HTML5
The definition of 'HTMLSelectElement' in that specification.
Recommendation Initial definition, snapshot of WHATWG HTML Living Standard.

Browser compatibility

 
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/htmlselectelement/form

API HTMLSelectElement Property Read-only Reference