Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

1 Answer

Kevin Korte
Kevin Korte
28,148 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.