Codecademy Forums

FAQ: Learn HTML: Forms - Adding a Label

when submitting a form, the value of the name attribute is used,simple example:,js,output

see how i use username (value of name attribute) to retrieve the value from the form element?

for and id associate the label with the input element.

I think it’s starting to make sense. So in this example

<label for="name">Who Are You?</label>

The element designates the section of the code that will output, and so ‘name’ is arbitrary. It just makes deciphering the code easier to know what is being referenced?

<input type="text" name="name" id="name">

The element then calls out the type of input as ‘text’ as opposed to an integer or something else. And the ‘name’ and ‘id’ are simply references to the section of the code that designates this particular field. Is that correct? And if so, are the call outs for ‘name’ and ‘id’ redundant?

id and name have distinctly different purposes, so clearly they are not redundant.

Every form control that is intended to be transmitted to a server based handler on Submit will have a unique name. When the user clicks Submit, the form is parsed into key-value pairs in a special POSTDATA object. The name is the key, and control value is the value in this pair.

id is a page fragment identifier, and ties back to the label attribute, for. It has no role in the handling of the form data.

1 Like