Attributes

So I just started learning about , and I keep getting confused about the purpose of what they do. So far there is for, id, type, name, value
So for is used in labels to assign a name,
Id is used in input to link it with a label, based on the ‘for’ of the label
type is used to add fancy stuff like checkboxes, etc.
What I don’t understand is what the name and value are used for, and why we need them. I also listed what I (think) understand above to see if I have any misconceptions that need to be corrected.

~Thanks.

value does what it says, it give the input element a value. So you can pre-load a certain field. This can be useful when a user is updating information (you want to set the fields with there existing username and so forth) or you already want to check a checkbox.

Normally, forms are submitted, validated and stored, the name attribute allows you to identify the field at the back-end.

so if you have:

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

and the user types: hello world in the input field, username => 'hello world' is send back to the server.

1 Like