diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/htmlformelement/elements | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/ru/web/api/htmlformelement/elements')
-rw-r--r-- | files/ru/web/api/htmlformelement/elements/index.html | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/files/ru/web/api/htmlformelement/elements/index.html b/files/ru/web/api/htmlformelement/elements/index.html new file mode 100644 index 0000000000..dbd4e1ddcd --- /dev/null +++ b/files/ru/web/api/htmlformelement/elements/index.html @@ -0,0 +1,100 @@ +--- +title: HTMLFormElement.elements +slug: Web/API/HTMLFormElement/elements +translation_of: Web/API/HTMLFormElement/elements +--- +<div>{{APIRef("HTML DOM")}}</div> + +<p><span class="seoSummary">The {{domxref("HTMLFormElement")}} property <code><strong>elements</strong></code> returns an {{domxref("HTMLFormControlsCollection")}} listing all the form controls contained in the {{HTMLElement("form")}} element.</span> Independently, you can obtain just the number of form controls using the {{domxref("HTMLFormElement.length", "length")}} property.</p> + +<p>You can access a particular form control in the returned collection by using either an index or the element's {{domxref("Element.name", "name")}} or {{domxref("Element.id", "id")}}.</p> + +<p>Prior to HTML 5, the returned object was an {{domxref("HTMLCollection")}}, on which <code>HTMLFormControlsCollection</code> is based.</p> + +<div class="note"> +<p><strong>Note:</strong> Similarly, you can get a list of all of the forms contained within a given document using the document's {{domxref("Document.forms", "forms")}} property.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox notranslate"><em>nodeList</em> = <em>HTMLFormElement</em>.elements +</pre> + +<h3 id="Value">Value</h3> + +<p>An {{domxref("HTMLFormControlsCollection")}} containing all non-image controls in the form. This is a live collection; if form controls are added to or removed from the form, this collection will update to reflect the change.</p> + +<p>The form controls in the returned collection are in the same order in which they appear in the form by following a preorder, depth-first traversal of the tree. This is called <strong>tree order</strong>.</p> + +<p>{{page("/en-US/docs/Web/API/HTMLFormElement", "Elements that are considered form controls")}}</p> + +<h2 id="Example">Example</h2> + +<h3 id="Quick_syntax_example">Quick syntax example</h3> + +<p>In this example, we see how to obtain the list of form controls as well as how to access its members by index and by name or ID.</p> + +<pre class="brush: html notranslate"><form id="my-form"> + <input type="text" name="username"> + <input type="text" name="full-name"> + <input type="password" name="password"> +</form></pre> + +<pre class="brush:js notranslate">var inputs = document.getElementById("my-form").elements; +var inputByIndex = inputs[0]; +var inputByName = inputs["username"]; +</pre> + +<h3 id="Accessing_form_controls">Accessing form controls</h3> + +<p>This example gets the form's element list, then iterates over the list, looking for {{HTMLElement("input")}} elements of type <code><a href="/en-US/docs/Web/HTML/Element/input/text">"text"</a></code> so that some form of processing can be performed on them.</p> + +<pre class="brush: js notranslate">var inputs = document.getElementById("my-form").elements; + +// Iterate over the form controls +for (i = 0; i < inputs.length; i++) { + if (inputs[i].nodeName === "INPUT" && inputs[i].type === "text") { + // Update text input + inputs[i].value.toLocaleUpperCase(); + } +} +</pre> + +<h3 id="Disabling_form_controls">Disabling form controls</h3> + +<pre class="brush: js notranslate">var inputs = document.getElementById("my-form").elements; + +// Iterate over the form controls +for (i = 0; i < inputs.length; i++) { + // Disable all form controls + inputs[i].setAttribute("disabled", ""); +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-form-elements', 'HTMLFormElement.elements')}}</td> + <td>{{ Spec2('HTML WHATWG') }}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("DOM2 HTML", "html.html#ID-76728479", "HTMLFormElement.elements")}}</td> + <td>{{Spec2("DOM2 HTML")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.HTMLFormElement.elements")}}</p> |