HTML form Attribute
Example
<form action="action.php" method="get" id="formId">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname">
</form>
<button type="submit" form="formId" value="Submit">Submit</button>
Meaning
The form attribute should be set to a string that corresponds to the id of the form element is associated with.
Standard Syntax
<element form="formId">
Applies to:
The form attribute can be used on the following element:
| Element | Attribute |
|---|---|
| <button> | form |
| <fieldset> | form |
| <input> | form |
| <meter> | form |
| <object> | form |
| <output> | form |
| <select> | form |
| <textarea> | form |
Advertisement
Attribute Values
| Value | Description |
|---|---|
| formId | The value of this attribute must be the id attribute of a <form> element in the same document. |
More Examples
Example
<form action="action.php" method="get" id="form1">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" form="form1"><br>
<input type="submit">
</form>
<fieldset form="form1">
<legend>User info:</legend>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">
</fieldset>
Example
<form action="action.php" id="form1">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">
Example
<form action="action.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<label for="anna">Your score:</label>
<meter id="anna" form="form1" name="anna" min="0" low="40" high="95" max="100" value="80"></meter>
Example
<form action="action.php" id="object1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<object form="object1" data="demo/image.jpg" width="300" height="150"></object>
Example
<form id="form1" oninput="result.value=parseInt(a.value)+parseInt(b.value)">
<input type="range" id="b" name="b" value="50" /> +
<input type="number" id="a" name="a" value="10" />
<input type="submit">
</form>
=
<output form="form1" name="result" for="a b">50</output>
Example
<form action="action.php" id="langform">
<input type="submit">
</form>
<label for="lang">Choose your option:</label>
<select name="language" form="langform" id="lang">
<option value="HTML">HTML</option>
<option value="CSS">CSS</option>
<option value="JavaScript">JavaScript</option>
</select>
Example
<form action="action.php" id="form1">
<input type="submit" value="Submit">
</form>
<br><br>
<label for="demo">textarea demo:</label>
<textarea form="form1" id="demo" name="textareaText">
Hello world!
</textarea>