HTML - attributes - form

revision:


Content

"form" attribute : specifies the form the element belongs to syntax some excamples


"form" attribute : specifies the form the element belongs to

top

The value of this attribute must be equal to the id attribute of a <form> element in the same document.
The form attribute can be used on the following elements: <button>, <fieldset>, <input>, <label>, <meter>, <object>, <output>, <select>, <textarea>.


syntax

top

<element form="form_id">


some examples

top


The button below is outside the form element, but still part of the form.

codes:
                    <form style="margin-left:5vw;" action="action_page.php" method="get" id="nameform">
                        <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>
                    <p class="spec">The button below is outside the form element, but still part of the form.</p>
                    <button style="margin-left:5vw;" type="submit" form="nameform" value="Submit">Submit</button>
                

The fieldset below is outside the form, but still a part of the form.

Personalia:
codes
                    <form style="margin-left:5vw;" action="action_page.php" method="get" id="form1">
                        <label for="favcolor">What is your favorite color?</label>
                        <input type="text" id="favcolor" name="favcolor">
                        <input type="submit">
                    </form>
                    <p class="spec">The fieldset below is outside the form, but still a part of the form.</p>
                    <fieldset style="margin-left:5vw;" form="form1">
                        <legend>Personalia:</legend>
                        <label for="fname">First name:</label>
                        <input type="text" id="fname" name="fname" form="form1"><br>
                        <label for="lname">Last name:</label>
                        <input type="text" id="lname" name="lname" form="form1">
                    </fieldset>