While filling in forms on web pages, we may want to restrict the user from changing the value of the input element until some other condition has been met, or we may want to restrict some buttons to the users who don’t have sufficient access to specific functionalities.
To do this, we have the disabled
attribute in HTML for the input element. When we apply the disabled
attribute to the input element, it will become unusable
and unclickable
.
We can use the following syntax for enabling this attribute:
<input disabled>
Let’s look at an example.
In the following example, we create two buttons:
disabled
attribute on it.disabled
attribute on it. This becomes unusable.<html><head></head><body><div id="content"><p>button without disabled attribute:</p><input type="button" value="Delete"><p>button with disabled attribute:</p><!-- disabled attribute --><input type="button" value="Delete" disabled></div></body></html>