HTMLフォーム属性
定義と使用法
属性はform
、要素が属するフォームを指定します。
この属性の値は
、同じドキュメント内の要素のid
属性と同じである必要があります。
<form>
に適用されます
このform
属性は、次の要素で使用できます。
要素 | 属性 |
---|---|
<ボタン> | 形 |
<フィールドセット> | 形 |
<入力> | 形 |
<ラベル> | 形 |
<メーター> | 形 |
<オブジェクト> | 形 |
<出力> | 形 |
<選択> | 形 |
<textarea> | 形 |
例
ボタンの例
フォームの外側にあるボタン(ただし、フォームの一部):
<form action="/action_page.php" method="get" id="form1">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
<button type="submit" form="form1" value="Submit">Submit</button>
フィールドセットの例
フォームの外側にある<fieldset>要素(ただし、フォームの一部):
<form action="/action_page.php" method="get" id="form1">
What is your favorite color? <input type="text" name="fav_color"><br>
<input type="submit">
</form>
<fieldset form="form1">
Name: <input type="text" name="username"><br>
Email: <input type="text" name="usermail"><br>
</fieldset>
入力例
HTMLフォームの外部にある入力フィールド(ただし、フォームの一部):
<form action="/action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
ラベルの例
フォームの外側にある<label>要素(ただし、フォームの一部):
<form action="/action_page.php" id="form1">
<input type="radio" id="html" name="fav_language" value="HTML"><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label
for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language"
value="JavaScript">
<label for="javascript">JavaScript</label><br><br>
<input type="submit" value="Submit">
</form>
<label
for="html">HTML</label>
メーターの例
フォームの外側にある<meter>要素(ただし、フォームの一部):
<form action="/action_page.php" method="get" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<meter form="form1" name="x1" min="0" low="40" high="90"
max="100" value="95"></meter>
オブジェクトの例
フォームの外側にある<object>要素(ただし、フォームの一部):
<form action="/action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<object data="helloworld.swf" height="400" width="400" form="form1" name="obj1"></object>
出力例
フォームの外側にある<output>要素(ただし、フォームの一部):
<form action="/action_page.php" id="numform"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
<input type="range" id="a" name="a" value="50">100
+<input type="number" id="b" name="b" value="50">
<br><br>
<input type="submit">
</form>
<output form="numform" name="x" for="a b"></output>
例を選択
フォームの外側にあるドロップダウンリスト(ただし、フォームの一部):
<form action="/action_page.php" id="carform">
Firstname:<input type="text" name="fname">
<input type="submit">
</form>
<select name="carlist" form="carform">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
Textareaの例
フォームの外側にあるテキスト領域(ただし、フォームの一部):
<form action="/action_page.php" id="usrform">
Name: <input type="text" name="usrname">
<input type="submit">
</form>
<textarea name="comment" form="usrform">Enter text here...</textarea>
ブラウザのサポート
このform
属性では、要素ごとに次のブラウザがサポートされています。
Element | |||||
---|---|---|---|---|---|
button | 10.0 | Not supported | 4.0 | 5.1 | 9.5 |
fieldset | Not supported | Not supported | Not supported | Not supported | Not supported |
input | 9.0 | Not supported | 4.0 | 5.1 | 10.6 |
label | Yes | Yes | Yes | Yes | Yes |
meter | Not supported | Not supported | Not supported | Not supported | Not supported |
object | Not supported | Not supported | Not supported | Not supported | Not supported |
output | Yes | Not supported | Yes | Yes | Yes |
select | Yes | Not supported | Yes | Yes | Yes |
textarea | Yes | Not supported | Yes | Yes | Yes |