Home  >  Q&A  >  body text

Disabled form inputs will not appear in requests

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粉860897943P粉860897943371 days ago665

reply all(2)I'll reply

  • P粉722409996

    P粉7224099962023-10-15 17:03:45

    Use Jquery and send data using ajax, you can solve your problem:

    <script>
    
    $('#form_id').submit(function() {
        $("#input_disabled_id").prop('disabled', false);
    
        //Rest of code
        })
    </script>

    reply
    0
  • P粉298305266

    P粉2983052662023-10-15 10:30:33

    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,

    <input type="textbox" name="Percentage" value="100" disabled="disabled" />

    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,

    <input type="textbox" name="Percentage" value="100" readonly="readonly" />

    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.

    reply
    0
  • Cancelreply