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

Why 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
huckleberry
14,632 Points

Well 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 :)

LaVaughn Haynes
LaVaughn Haynes
12,394 Points

You 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.

Oh , 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
huckleberry
14,632 Points

There 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.