0

I have the next checkbox:

<input type="checkbox" value="true" name="permanentEmployee" checked="" id="permanentEmployee" disabled="">

I've set the attribute disabled to true and submitted the form

$("#permanentEmployee").prop('disabled', true);`

On server side, if I do:

request.getParameter("permanentEmployee")

I get the value as Null, though I get the the correct value (i.e True) if I don't disable the checkbox. Why am I not getting the disabled checkbox value as True even if it is checked?

Marty McVry
  • 2,838
  • 1
  • 17
  • 23
user3198603
  • 5,528
  • 13
  • 65
  • 125

3 Answers3

1

Disabled form elements are not sent via form submit. You can consider using read-only instead

One idea would be

$('#permanentEmployee').click(function(){
        return false; // even if the user clicks on it it will not change
});

$('#permanentEmployee').prop('checked', true);

http://jsfiddle.net/Spokey/M3LfA/1/

Spokey
  • 10,974
  • 2
  • 28
  • 44
1

Just before submitting the form (onsubmit listener) you could enable the checkbox.

James
  • 20,957
  • 5
  • 26
  • 41
0

Disabled check boxes (and probably other form elements) are not sent to the server.

There are a couple of solutions here: How to ensure a <select> form field is submitted when it is disabled?

Community
  • 1
  • 1
Bob Brown
  • 1,463
  • 1
  • 12
  • 25