-1

I'm trying to get the values from some checkboxes. Some are unchecked, some are checked but disabled. In both these cases, no POST data will be sent to the server by the browser.

What I'm wondering, is how can I know that the checkbox was unchecked, or disabled but checked?

laurent
  • 88,262
  • 77
  • 290
  • 428

2 Answers2

2

You can only check, if a checkbox was checked (send) or not (not send).

If you realy want to know this server side, you can make use of AJAX or set a hidden input before submit.

You can check the state of the checkbox here

document.getElementById("myBox").disabled
Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
  • I was hoping for a solution that didn't involve JavaScript hacks, but it seems it's the only solution. For a minute I thought using the readonly attribute was fine but, although the checkbox is grayed out, it can still be changed. – laurent Dec 21 '14 at 14:03
  • 1
    If the user is not be able to change it, why not safe the state into a `Session`? – Christian Gollhardt Dec 21 '14 at 14:06
1

Unfortunately the disabled checkbox values are never sent to POST. What I would do is make a small JS code to enable the checkboxes right before the form is sent, or use hidden fields which mimic the checkboxes' values.

numsu
  • 472
  • 3
  • 10