I’m always feel the disabled attribute for HTML <input> and all is twisting my brain. Why choose a negated attribute name, isn’t enabled more intuitive?
Just compare:
enabled=advancedUser
disabled=not(advancedUser)
enabled=not(locked)
disabled=locked
enabled=advancedUser and not(locked)
disabled=not(advancedUser) or locked
disabled=not(advancedUser and not(locked))
The fundamental reason behind this is that it was a later addition to the HTML input fields, and needed to be that way to maintain backward compatibility with existing web pages.
When the
<input>tag was originally defined, its functionality was extremely limited. It did not havedisabledorreadonlyattributes, nor many of the other properties we take for granted today.These were all added later, but by the time they were added, many web sites were already using
<input>fields, so the ability to disable it had to work without affecting existing code that didn’t use it. Therefore the default state had to beenabled.It also had to be a boolean flag, which is why it is
disabledrather thanenabled=true. The latter would have been a key-value pair attribute. This wouldn’t have been a good choice.Consider the following:
The browser would have had to be able to cope with a huge number of possible values. Making it a boolean flag simplifies things enormously. It makes the spec easier to understand, both for the web site developer and the browser developer.
The other thing to bear in mind is that the time when this property was added to HTML was in the middle of the so-called ‘browser wars’. Many features were being added to the competing web browsers, in a hurry and without the benefit of formal specs, and many features were added which we can indeed look back on and wish it were slightly different.
I don’t believe this is one of those features: the
disabledflag is perfectly logical really if you stop and think about it. But it’s quite possible that it may have been better designed if the browser developers had been co-operating a bit more back then.But whatever the case, the situation today is that this is what we have. The HTML spec may be evolving, but existing features such as this are not going to change now.