Skip to content Skip to sidebar Skip to footer

How To Use "form=form_id" Attribute In Html5 Input

I'm trying to use 'form' attribute for html5 input as described here: [1] http://www.w3schools.com/html5/att_input_form.asp [2] http://www.w3schools.com/html5/tryit.asp?filename=tr

Solution 1:

Because you're trying to assign two form owners.

"A form-associated element is, by default, associated with its nearest ancestor form element (as described below), but may have a form attribute specified to override this."

http://www.w3.org/TR/html5/forms.html#association-of-controls-and-forms

This attribute just allows markup flexibility, it doesn't change the form ownership paradigm from the previous spec.


Solution 2:

I could not find anything in the W3C HTML5 specification to support the statement on the www.w3schools.com site that input element can belong to 2 or more forms. The input element's owner is always mentioned in singular and never as a list. Furthermore on developer.mozilla.org there is explicit statement about the input association with one form only. The description of the form attribute states:

form: A string indicating which element this input is part of. An input can only be in one form.


Solution 3:

An input field can only be on one form. It is better to include it within the form scope, for clarity.

Use also name instead of only id on your forms. Although html5 supports it, what with older browsers? What with IE?

<form action="demo_form.asp" name="form1" id="form1">

<form action="demo_form.asp" name="form2" id="form2">

Solution 4:

use javascript and name form on submit

<form action="demo_form.asp" onsubmit= 'this.id="form1"'>
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>

<form action="demo_form.asp" onsubmit= 'this.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" />

Post a Comment for "How To Use "form=form_id" Attribute In Html5 Input"