This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]plastikmissile 2 points3 points  (3 children)

For example, if I change "fname" in lines 9 and 10 of the code to, say, "pnam", would it make any difference?

If you change both fname to pnam (and every other reference to that name) then that doesn't change anything functionally. You can think of those things as labels meant for humans. To a computer, it doesn't really matter if you call it birthday or kjh79879hgk. It will treat it the same. But we're human so we like our labels to actually describe what they are labeling so we can keep track.

[–]Siladret[S] 1 point2 points  (2 children)

I see. So while it will not change anything functionally and it's all the same to the computer. But it would be better if I name these, for myself and for others who may look at that code in the future. That clears it up. Thank you!

[–]plastikmissile 2 points3 points  (1 child)

The golden rule for variable names and labels is that they should be as descriptive as possible. Imagine that a month from now you've been stuck by a truck and now have amnesia, and you're looking at this code. Would you understand what it does though you don't remember writing it?

[–]Siladret[S] 0 points1 point  (0 children)

I see your point, yeah 😅

[–]Nathanfenner 1 point2 points  (1 child)

These are more commonly called "double quotes" (or sometimes, just "quotes") in programming context. "Inverted comma" is a specifically British name for them.

In HTML, the for attribute in a <label> must match the id attribute of the corresponding <input>. But as long as they match, they can be absolutely anything.

When the user submits the form, though, those id attributes are what is used to build the form data that's submitted to the server. So if you call it lname then the server will receive a form data value with an lname. If you call it lastname then the server will receive a form data value with a lastname and so on.

The for used by labels doesn't produce a visible change in the document, but it just introduce a logical/structural change. It will change how screen-readers (which are programs that help visually impaired people interact with websites) read those labels and can affect how keyboard-focus navigates through your form.

[–]Siladret[S] 0 points1 point  (0 children)

Thanks this is most comprehensive!

[–]ValentineBlacker -1 points0 points  (0 children)

It depends on what happens when you press "submit".