Disabled form inputs do not appear in the request

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

Is there any workaround for this without adding a hidden field?

<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>

Elements with Disabled attribute are not submitted or you can say their values are not posted (see the second bullet point under Step 3 in the spec for building the form data set).

Ie,

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

FYI,

  • Disabled controls do not receive focus.
  • Disabled controls are skipped in tabbing navigation.
  • Disabled controls cannot be successfully posted.
  • You can use readonly attribute in your case, by doing this you will be able to post your field's data.

    Ie,

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

    FYI,

  • Read-only elements receive focus but cannot be modified by the user.
  • Read-only elements are included in tabbing navigation.
  • Read-only elements are successfully posted.

  • 使用jquery并用ajax发送数据,你可以解决你的问题:

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

    If you absolutely have to have the field disabled and pass the data you could use a javascript to input the same data into a hidden field (or just set the hidden field too). This would allow you to have it disabled but still post the data even though you'd be posting to another page.

    链接地址: http://www.djcxy.com/p/4496.html

    上一篇: 禁用Chrome自动填充

    下一篇: 禁用的表单输入不会出现在请求中