CSS CSS Selectors Going Further with Attribute Selectors and Pseudo-Classes Element States Pseudo-Classes

1 Answer

Kevin Korte
Kevin Korte
28,092 Points

Could be a couple of times to use it.

Most commonly, when you want to restrict a form element from being populated before another. Quite commonly, you'll see chainable select dropdowns.

Maybe you have select dropdowns where you pick a country, and than city. So you might first make the country dropdown populate, and make the city dropdown disabled, and than when the user picks a country, you populate the city dropdown and enable it, because you want the user to pick a country before the city.

Another reason is maybe it's a contact form, and the user is logged in (so you have their active email address), you may want to show them that their email address is included in the form, but not allow them to edit it (because they need to be who they say they are).

Or maybe a price field. They've added the widget to buy, so when they go to buy it, you can show them the price in a price input but disable it's input field. (Hint, this is easy to get around, all the user has to do is open up their inspector tool and they can edit the HTML value of the disabled input to whatever they want, like $1, before submitting the form, so you can't rely on a disabled form input to protect your sensitive data like a price or email address, but it will help cut down on "accidental" changes.)

Those are some scenarios I can think of the. The chainable form inputs are the most common.