Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 
like image 226
hazzik Avatar asked Sep 09 '11 04:09

hazzik


People also ask

Do disabled form fields get submitted?

If a field is disabled , the value of the field is not sent to the server when the form is submitted. If a field is readonly , the value is sent to the server.

How do I post a disabled field?

To submit the value of a disabled input field with HTML, we replace the disabled attribute with the readonly attribute. to set the readonly attribute to readonly . This way, the user won't be able to interact with the input, but the input value will still be submitted.

How get textbox value from disabled in PHP?

var sum = (number1 + number2); $('#sum'). val(sum);


1 Answers

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

I.e.,

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

FYI, per 17.12.1 in the HTML 4 spec:

  1. Disabled controls do not receive focus.
  2. Disabled controls are skipped in tabbing navigation.
  3. 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.

I.e.,

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

FYI, per 17.12.2 in the HTML 4 spec:

  1. Read-only elements receive focus but cannot be modified by the user.
  2. Read-only elements are included in tabbing navigation.
  3. Read-only elements are successfully posted.
like image 126
AlphaMale Avatar answered Oct 06 '22 20:10

AlphaMale