[Solution & reason] data cannot be transferred to the background after the disabled attribute is added to the input tag.

When modifying personal information in the implementation project, the personal ID and username cannot be modified according to my logic.
So we added disabled to the input tag to make it unmodifiable.
But after pressing the button, instead of the data being sent to the background, the corresponding property becomes null.

  • The problem code is as follows
<input type="hidden" name="bookType" value="0">
            <p>
                <span class="name-icon">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                I&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D: <input type="text" name="id"  disabled="true"  value="${user.id}"  >
            </p>
        <p>
            <span class="name-icon">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            //Last & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & first name: < input type = "text" name = "username" disabled = "true" value = "${user. Username}" >
        </p>
  • Modification method
<input type="hidden" name="bookType" value="0">
            <p>
                <span class="name-icon">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                I&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D: <input type="text" name="id"  readonly="true"  value="${user.id}"  >
            </p>
        <p>
            <span class="name-icon">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            //Last & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & first name: < input type = "text" name = "username" readonly = "true" value = "${user. Username}" >
        </p>

Reason

The element of the disabled attribute in the form form does not participate in the form submission

The difference between the disabled and readonly attributes

  • readonly is to lock this control by not modifying it on the interface (but by javascript).
  • Disabled and readonly have the same thing. They can also lock this control. The user cannot change its value, but disabled is more thorough. This is to make the control completely unusable and completely invalid, including changing its background color (if you don't believe it, you need to modify an input text box that has been disabled and find that this is in vain). If it is a checkbox, you can't select it. In it.
  • All controls have the disabled property, but not necessarily the readonly property, such as the select drop-down box.

Keywords: Attribute Javascript

Added by tobykw13 on Fri, 01 Nov 2019 10:04:08 +0200