Horje
How to create HTML form Attribute in Input

The input form attribute specifies the form the <input> element belongs to.

The value of this attribute must be equal to the id attribute of the <form> element it belongs to.


Example of creating HTML form Attribute in Input

An input field located outside of the HTML form (but still a part of the form):
index.html
Example: HTML
<form action="/action_page.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">

Output should be:

Example of creating HTML form Attribute in Input

Full Completed Code of creating HTML form Attribute in Input

The form attribute specifies the form an input element belongs to. The "Last name" field below is outside the form element, but still part of the form.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h1>The input form attribute</h1>

<p>The form attribute specifies the form an input element belongs to.</p>

<form action="/action_page.php" id="form1">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <input type="submit" value="Submit">
</form>

<p>The "Last name" field below is outside the form element, but still part of the form.</p>

<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">

</body>
</html>

Output should be:

Full Completed Code of creating HTML form Attribute in Input





Category:
Web Tutorial
Sub Category:
HTML Input Attributes
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference