Values of disabled inputs will not be submitted

Form SubmitDisabled InputFormsHttp Post

Form Submit Problem Overview


This is what I found by Firebug in Firefox.

Values of disabled inputs will not be submitted

Is it the same in other browsers?

If so, what's the reason for this?

Form Submit Solutions


Solution 1 - Form Submit

disabled input will not submit data.

Use the readonly attribute:

<input type="text" readonly />

Source here

Solution 2 - Form Submit

Yes, all browsers should not submit the disabled inputs, as they are read-only.

More information (section 17.12.1)

> ### Attribute definitions > > disabled [CI] When set for a form control, this Boolean attribute > disables the control for user input. When set, the disabled attribute > has the following effects on an element: > > > > - Disabled controls do not receive focus. > - Disabled controls are skipped in tabbing navigation. > - Disabled controls cannot be successful. > > The following elements support the disabled attribute: BUTTON, INPUT, > OPTGROUP, OPTION, SELECT, and TEXTAREA. > > This attribute is inherited but local declarations override the > inherited value. > > How disabled elements are rendered depends on the user agent. For > example, some user agents "gray out" disabled menu items, button > labels, etc. > > In this example, the INPUT element is disabled. Therefore, it cannot > receive user input nor will its value be submitted with the form. > > > > Note. The only way to modify dynamically the value of the disabled > attribute is through a script.

Solution 3 - Form Submit

You can use three things to mimic disabled:

  1. HTML: readonly attribute (so that the value present in input can be used on form submission. Also the user can't change the input value)

  2. CSS: 'pointer-events':'none' (blocking the user from clicking the input)

  3. HTML: tabindex="-1" (blocking the user to navigate to the input from the keyboard)

Solution 4 - Form Submit

They don't get submitted, because that's what it says in the W3C specification.

> 17.13.2 Successful controls > > A successful control is "valid" for submission. [snip] > > * Controls that are disabled cannot be successful.

In other words, the specification says that controls that are disabled are considered invalid for submission.

Solution 5 - Form Submit

There are two attributes, namely readonly and disabled, that can make a semi-read-only input. But there is a tiny difference between them.

<input type="text" readonly />
<input type="text" disabled />
  • The readonly attribute makes your input text disabled, and users are not able to change it anymore.
  • Not only will the disabled attribute make your input-text disabled(unchangeable) but also cannot it be submitted.

jQuery approach (1):

$("#inputID").prop("readonly", true);
$("#inputID").prop("disabled", true);

jQuery approach (2):

$("#inputID").attr("readonly","readonly");
$("#inputID").attr("disabled", "disabled");

JavaScript approach:

document.getElementById("inputID").readOnly = true;
document.getElementById("inputID").disabled = true;

PS disabled and readonly are standard html attributes. prop introduced with jQuery 1.6.

Solution 6 - Form Submit

Disabled controls cannot be successful, and a successful control is "valid" for submission. This is the reason why disabled controls don't submit with the form.

Solution 7 - Form Submit

select controls are still clickable even on readonly attrib

if you want to still disable the control but you want its value posted. You might consider creating a hidden field. with the same value as your control.

then create a jquery, on select change

$('#your_select_id').change(function () {
    $('#your_hidden_selectid').val($('#your_select_id').val());
});

Solution 8 - Form Submit

Here's the Solution and still using disabled property. First disable your inputs on load.

$(document).ready(function(){
  $("formselector:input").prop("disabled",true);
  $( "formselector" ).submit(function( event ) {
      $(":disabled").prop("disabled",false);
      });
});

on submit enable all of them. this will assure everything is posted

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionomgView Question on Stackoverflow
Solution 1 - Form SubmitFred KView Answer on Stackoverflow
Solution 2 - Form SubmitAzizView Answer on Stackoverflow
Solution 3 - Form SubmitNovice_JSView Answer on Stackoverflow
Solution 4 - Form SubmitMiffTheFoxView Answer on Stackoverflow
Solution 5 - Form SubmitElyas HadizadehView Answer on Stackoverflow
Solution 6 - Form SubmitJuan de ParrasView Answer on Stackoverflow
Solution 7 - Form SubmitJohnineView Answer on Stackoverflow
Solution 8 - Form SubmitMohamad ElnaqeebView Answer on Stackoverflow