Why are checkboxes not posted when unchecked?

26 Views Asked by At

I use a library which constructs a Javascript object from a form's elements : $("#frm").serializeJSON()

Here is the website of the library.

So at runtime when a checkbox is not checked then it does not appear inside the Javascript object constructed from $("#frm").serializeJSON(). Although I set a name attribute to the checkbox element. So why ?

1

There are 1 best solutions below

2
Roman Lytvynov On BEST ANSWER

You should provide checkboxUncheckedValue property with suitable value for your case.

For example

$("#frm").serializeJSON({checkboxUncheckedValue: "false"})

Check the doc for more details https://github.com/marioizquierdo/jquery.serializeJSON?tab=readme-ov-file#include-unchecked-checkboxes