Are `name`, `id`, and `for` required? Can they be the same? And what is the relationship between them?

Why must there be a “name” and “for” attribute? Can’t the code work without them?

1 Like

What difference are there between name and id attribute?

4 Likes

the for attribute uses the id to associate input field and label, the id also can be used for styling

5 Likes

Do “id”, “name” and “for” attributes require the same name ?

id and for should have the same name, given this associates the label with the input element. name doesn’t have to be the same, but i quite often do, because you want to have a logic name (one that make sense for the input field)

5 Likes

What happens if we omit the attribute “for” in label tag.Does it makes any difference?

the for attribute associates the label with the input element, omitting could cause problems for disability aid tools for example.

1 Like

Why should the value in name attribute of input should match the value of for attribute of label?
I can understand for(of label) should match with id(of input).
It works just fine when name does not match with for. Why does the exercise insist on both values being the same?

the name attribute doesn’t have too match the for attribute, yet very often these names are the same. Why? Because its the most logic/descriptive name available.

in this exercise, why we don’t need to value?
as told previously, the input sent the user input with name=value to site, but here seem its ok to not using value. am i right?

the text area is not self closing, as such the value can be between the opening and closing tag (just like a paragraph, span and so forth), so we don’t need the value attribute

1 Like

thank you, but i ask about password input, not text area (of corse i did did not know the notice you mentioned, thanks for that )

i read text area, so that is what i answered

as for password input, using the value attribute will set the default for the input field (password in this case), we don’t want to set a default password (security risk/nightmare), so the user has to enter their password.

2 Likes

you’r right, thanks for answer. :ok_hand:

how do u give correct usernames and passwords for form submission

Like a login system? You would need to compare the username and password with stored credentials.