Good question! The name is primarily for use by the software. For example, in my database course, a user might fill out a form with their rating of a dish on Wellesley Fresh. The input might be named rating and have a value of 4. So the back end gets rating=4.
Meanwhile, the label is for the user. That rating of 4 might be a radio button with a label of "good". (Or maybe "bon" if the page is in French). Or it might be a similar drop-down menu. Like these:
One example is the SELECT menu above. The structural should work, but it sometimes confuses the validator, while the FOR/ID doesn't confuse the validator.
Another example is where the text inputs and labels are in two columns of a table. (We haven't learned tables, because they aren't often necessary, but they can be useful sometimes.)
| label | value |
|---|---|
The MENU tag doesn't exist. It was just there to
distract you from the correct answer.
Great question! If browsers don't understand a type
(like time and range), they fall back to a
text box, since that's universal. So, that behavior is built-in. But
it's great that you are thinking about that!
Also, transparency is pretty widely supported nowadays, so the color backup is less important than it once was. But again, it's good to think about it.
Yes! Later in the course (if there's time), we'll learn how to add some JavaScript to do form validation: checking that inputs are proper, including things like you describe. There are some built-in mechanisms (patterns and such), but also a way to hook our own JS into the form mechanism, so that our code gets run instantly and automatically, giving the user immediate feedback.
But it sound like you don't even want to wait that long. Yes,
it's possible to hijack the keyboard event handler (using
the input event) so that the user can't even type a
letter into a text box that is supposed to hold a number, for
example. So, we kinda already know how to do that.
I think you are talking about this:
I appreciate the careful reading you have done. However, this is a topic we will discuss later in the course when we get to form validation.
In a nutshell, required form inputs have
a :required pseudo-class on them
and invalid form inputs get the :invalid
pseudo-class added to them by the validation code. This CSS changes
the border to highlight invalid form inputs.
Absolutely! That's what we'll do next time, after the break!
Great!