What is ReadOnly and Disabled attribute in HTML?
What is ReadOnly and Disabled attribute in HTML?
ReadOnly attribute is a input type field in HTML which specify read only function. ReadOnly attribute is a Boolean(Yes/No) attribute. Readonly field cannot be modified. The element will be enabled but its contents cannot be edited.The ReadOnly attribute is applied to input and Textarea.
Example of ReadOnly attribute
<html>
<title>Readonly</title>
<body>
Name: <input type="text" name="Name" value="Manish" readonly><br>
<input type="submit" value="Submit">
<body>
<html>
Disabled attribute in input field specifies that the input element is disabled. Disabled attribute is Bollean attribute.Disabled element in form cannot be submitted. The disabled attribute is applied in following field button,Fieldset,Input,Optgroup,option,select,Textarea, etc. The disabled attribute can be set to prevent user from using the element till some specified condition has been met.
Example of disabled button.
<html>
<title>Disabled</title>
<body>
<button type="button" disabled>Click Me!</button>
</body>
</html>
Difference between Readonly attribute and Disabled attribute.
Readonly attribute
1. TextBox and TextArea of Html input can be set as to ReadOnly.
2. Cursor can be shown in ReadOnly TextBox or TextArea.
3. Focus can be set in ReadOnly element.
4. During TAB navigation ReadOnly elenments are focused.
5. ReadOnly elements is sent to server during Form Submission.
Disabled attribute
1. All elements can be set as Disabled.
2. Cursor is not shown in Disabled TextBox and TextArea.
3. Focus cannot be set in Disabled element.
4. Elements which are disabled is not focused during TAB navigation.
5. Datas of disabled elements is not sent to server during Form Submission .
6.It appears uncolored in Browser.
Output of Readonly attribute
Output of Disabled attribute