aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/document/forms/index.html
blob: 7a8dcc4f534e62d80f2470ac2ba3643cb5fd62fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
title: Document.forms
slug: Web/API/Document/forms
tags:
  - API
  - DOM
  - Document
  - HTML DOM
  - HTML フォーム
  - フォーム
  - プロパティ
  - リファレンス
translation_of: Web/API/Document/forms
---
<p><span class="seoSummary">{{domxref("Document")}} インターフェイスの <strong><code>forms</code></strong> プロパティは読み取り専用で、文書内に含まれるすべての {{HTMLElement("form")}} を列挙した {{domxref("HTMLCollection")}} を返します。</span></p>

<div class="note">
<p><strong>メモ:</strong> 同様に、{{domxref("HTMLFormElement.elements")}} プロパティを使用すると、フォームコンポーネントのユーザー入力要素のリストにアクセスすることができます。</p>
</div>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox"><var>collection</var> = <em>document</em>.forms;</pre>

<h3 id="Value" name="Value"></h3>

<p>文書のすべてのフォームを列挙する {{domxref("HTMLCollection")}} オブジェクトです。コレクションのそれぞれの項目は、単一の <code>&lt;form&gt;</code> 要素を表す {{domxref("HTMLFormElement")}} です。</p>

<p>文書にフォームがない場合、返されるコレクションは空で、長さはゼロです。</p>

<h2 id="Example" name="Example"></h2>

<h3 id="Getting_form_information" name="Getting_form_information">フォーム情報の取得</h3>

<pre class="brush:html">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;

&lt;head&gt;
&lt;title&gt;document.forms example&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form id="robby"&gt;
  &lt;input type="button" onclick="alert(document.forms[0].id);" value="robby's form" /&gt;
&lt;/form&gt;

&lt;form id="dave"&gt;
  &lt;input type="button" onclick="alert(document.forms[1].id);" value="dave's form" /&gt;
&lt;/form&gt;

&lt;form id="paul"&gt;
  &lt;input type="button" onclick="alert(document.forms[2].id);" value="paul's form" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>

<h3 id="Getting_an_element_from_within_a_form" name="Getting_an_element_from_within_a_form">フォーム内要素の取得</h3>

<pre class="brush: js">var selectForm = document.forms[index];
var selectFormElement = document.forms[index].elements[index];
</pre>

<h3 id="Named_form_access" name="Named_form_access">名前付きフォームへのアクセス</h3>

<pre class="brush: html">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
  &lt;title&gt;document.forms example&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form name="login"&gt;
  &lt;input name="email" type="email"&gt;
  &lt;input name="password" type="password"&gt;
  &lt;button type="submit"&gt;Log in&lt;/button&gt;
&lt;/form&gt;

&lt;script&gt;
  var loginForm = document.forms.login; // Or document.forms['login']
  loginForm.elements.email.placeholder = 'test@example.com';
  loginForm.elements.password.placeholder = 'password';
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>

<h2 id="Specification" name="Specification">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">コメント</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', '#dom-document-forms', 'Document.forms')}}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 HTML', 'html.html#ID-1689064', 'Document.forms')}}</td>
   <td>{{ Spec2('DOM2 Events') }}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2>

<p>{{Compat("api.Document.forms")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li><a href="/ja/docs/Learn/HTML/Forms">HTML forms</a></li>
 <li>{{HTMLElement("form")}} および {{domxref("HTMLFormElement")}} インターフェイス</li>
</ul>

<div>{{APIRef("DOM")}}</div>