Disabled form inputs will not appear in requests
P粉860897943
P粉860897943 2023-10-14 18:01:00
0
2
463

I have some disabled inputs in my form and I want to send them to the server, but Chrome excludes them from the request.

Is there a way to solve this problem without adding hidden fields?

<form action="/Media/Add">
    <input type="hidden" name="Id" value="123" />

    <!-- this does not appear in request -->
    <input type="textbox" name="Percentage" value="100" disabled="disabled" /> 

</form>

P粉860897943
P粉860897943

reply all(2)
P粉298305266

Elements with the disabled attribute are not submitted, or you can say that their values ​​are not posted (see HTML 5 Specification for Building Form Datasets).

Right now,

FYI, as per 17.12.1 In the HTML 4 specification:

  1. Disabled controls will not receive focus.
  2. Disabled controls are skipped in tab navigation.
  3. Disabled controls cannot be published successfully.

You can use the readonly attribute in your case, by doing this you will be able to post the data of the field.

Right now,

For reference only, according to 17.12.2 In the HTML 4 specification:

  1. Read-only elements gain focus, but cannot be modified by the user.
  2. Contains read-only elements in tabbed navigation.
  3. The read-only element was published successfully.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!