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 trialArgzon Haziraj
Courses Plus Student 14,994 PointsWhy do we need to add disabled to input fields ?
I actually don't get it, why do we have to put a disabled input field if we don't want for someone to fill in it !!
Can someone please provide me some examples ?
3 Answers
huckleberry
14,636 PointsWell there may be times when there are certain fields that will exist on a form that will become active IF another field gets filled out or IF some checkbox gets checked, ya know? Think about it for a bit and I'm sure you'll remember plenty of times where you've seen this on a form.
Like, think of an online resume or medical information form.
"Have you been employed outside of the state of Virginia in the past 5 years?" Underneath is a blank text field that's inactive but if you check the yes box, it becomes active and says "please enter details here"
"Has anyone in your family ever had cardiovascular disease?" Underneath is a blank text field that's inactive but if you check the yes box, it becomes active and says "please enter relationship here"
etc..
I'm sure there's plenty of other examples you could think of now too :)
Argzon Haziraj
Courses Plus Student 14,994 PointsOh , thanks a lot. That brings me to it, i totally can figure it now !
I have an example : if a user have to fill some forms , i can keep the "Next" button disabled until all the inputs are filled with content ! GREAT :)
huckleberry
14,636 PointsThere ya go! Perfect example! Your example is actually probably the most commonly used instance of this so it's actually much better than my examples hahaha.
LaVaughn Haynes
12,397 PointsYou might use a disabled input to not allow a user to fill in information unless they meet some other condition. For example, I could have a check box on my form next to the question "Are you a student?" If you don't check it then the text fields for "School Name" and "School Address" should be disabled. Now if you do check it then I can enable the fields.