HTML Registration Form Step 42

Hello all,

I’ve managed to successfully complete this step, but that’s because I could idenitfy a pattern of which elements were to get a name attribute and copy the text of the other attribute identifiers.

However, I’m still lacking understanding of what exactly is going on here. I’m getting confused of all the identifiers that are saying the same thing. ie.

<label for=“age” …
<input id=“age” …

and now on top of that <input name=“age” id=“age”…

Can someone please explain to me exactly what is going on to link the labels and input elements and now the id and name attributes?

Thanks!

Hi @ScottKrukowski

The instructions asked you to use the name attribute.

From W3Schools:

The name attribute specifies the name of an <input> element.
The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted.
Only form elements with a name attribute will have their values passed when submitting a form.

So, the name attribute is only used in input elements.

In later steps the instructions will ask you to link the label element with the respective input element.

This occurs by placing an id attribute in the input element, and a for attribute in the nesting label element. The attribute value for each should match.

This is how input elements which are not nested in a label element are associated.

If the input element is nested in a label element then it is not necessary to add a for attribute to the label element.

From W3Schools:

When used together with the <label> element, the for attribute specifies which form element a label is bound to.
When used together with the <output> element, the for attribute specifies the relationship between the result of the calculation, and the elements used in the calculation.

So, the for attribute is only used in label and output elements.

In the case of label elements, when the input element is not nested.

Where as the id attribute can also be used to uniquely identify any element, for any reason.

From what I gather, when data is submitted via a form, it needs to be coded in a meaningful way for the next phase of processing and storage.

Happy coding