Reputation: 81
Recently I examined form attribute of label tag on W3C schools. Link to the page, which states:
The form attribute specifies one or more forms the element belongs to.
My understanding is that I can set 1 label for radio buttons that are present in 2 forms.
I tried to implement this in the following way:
<form id="form_1">
<p><input type=radio id="test"> Testing case 1</p>
<p><input type=radio> Testing case 2</p>
</form>
<form id="form_2">
<p><input type=radio> Testing case 3</p>
<p><input type=radio id="test"> Testing case 4</p>
</form>
<label for="test" form="form_1 form_2">Click to select testing case 1 and testing case 4</label>
As you can see, only testing case 1 is being selected when clicking on label, while testing case 4 radio-button no.
What do I misunderstand here?
Upvotes: 0
Views: 68
Reputation: 943098
No.
A label can only label a single form control. An element's id
must be unique within a document.
The form
attribute also only supports a single form id as its value.
The rules have not changed in the latest (as of the time of this answer) nightly draft.
W3C schools
There's no such thing. You are looking at W3Schools. They are not affiliated with the W3C but get a lot of reflected glory from having a similar name. This appears to be just another example of them being wrong.
Upvotes: 1