HTML form control disable property readonly vs disabled


There are two ways to disable form submission in HTML

1. Addreadonly='readonly'Properties

2. Adddisabled='disabled'Properties

For example:

<input type="text" value="" readonly="readonly" /> 
<input type="text" value="" disabled="disabled" />

Both controls in the example are not modifiable. But they also have some differences!

From the literal meaning, we can see that the control that tries the readonly property is “read-only”, while the trial of disabled is “disabled”. So what’s the difference between them?

A read-only control (a control that uses the readonly property) cannot be modified by the user with the mouse and keyboard, but the programmer can modify it with JavaScript. When submitting the form, the name and value of the control will be submitted to the server, that is, visible to the server.

The disabled control (which uses the disabled property) is not only not allowed to be modified by the user with the mouse and keyboard, but also invisible to the server. That is, when the form is submitted, its name and value will not be submitted to the server. Of course, programmers can also use JavaScript to modify their values.

This is the difference between them. After knowing the difference, we should know when to use which method. We must not be blind!


This article on the HTML form control disable property readonly vs disabled difference introduced here, more related HTML readonly disabled content, please search the previous articles of developeppaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!

Recommended Today

Huawei folding screen adaptation

Huawei folding screen adaptation scheme: Huawei has a system level support scheme for large screen equipment. Huawei has a parallel view and can support folding screen split screen display Huawei folding screen split screen display effect Introduction to Huawei parallel visionParallel horizon is a technology to display applications on large screen devices such as […]