Why do we need `for`, `id`, and `name`?

When writing the code for a Textarea Element, why do you need to add the for, id, and name?

<form> <label for="blog">New Blog Post: </label> <br> <textarea id="blog" name="blog" rows="5" cols="30"></textarea>
1 Like

you can, why shouldn’t this be possible? Default text is really useful

the for and id are used to associate the label and the element, the id can also be used for styling

the name is used form submission.

12 Likes

whats the big difference between id attribute and name atrribute

4 Likes

id is for styling and associating input element with label

name attribute is used when sending information to the back-end of your website.

22 Likes

are we learning back end in next section

1 Like

no, that would be throwing you into the deep. Of course you ca google about form submission to get a general idea. be careful not to drown.

9 Likes

I have tried so many times but this is not working. Text area code academy
Can someone please help!

The “for” attribute is used in the label as the identifier of the label element.
The “id” attribute is used in the elements like input and textarea with the same value as the attribute in the label.
This will help in making a connection with the label element. So during the form submission, it is known which label is connected to which element.

The Name attribute is the identifier for the text attribute. When the form is submitted, the value of the identifier i.e. name attribute is combined with what the user would input and sent.

4 Likes

to reference form data after a form is submitted,
the name attribute is used to reference elements in a JavaScript

so basically, name is sent to the for attribute

and id is used to make elements unique

Unfortunately, no, that is not how it works. name is only associated with the value attribute, neither id nor for.

<label for="username">Name</label>
<input id="username" placeholder="User Name">

Note how for is associated with the input bearing the id that matches.

1 Like

‘id’ is used as a reference point in CSS and Javascript code while name is essential for the server side in that it is used for all form elements that require feedback from the user lastly for is used for form control which corresponds to id

Remove the class and its value