JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<form id=foo>
<input type=checkbox name="c1"/>
<input type=checkbox name="c2"/>
<input type=checkbox name="c3"/>
<input type=submit value=submit />
</form>
JavaScript
$("#foo").submit(
function() {
var formEl = $(this);//get the reference of the form
debugger;
// Add an event listener on #foo submit action...
// For each unchecked checkbox on the form...
formEl.find("input:checkbox:not(:checked)").each(
// Create a hidden field with the same name as the checkbox and a value of 0
// You could just as easily use "off", "false", or whatever you want to get
// when the checkbox is empty.
function(index) {
var input = $("<input>");
input.attr('type', 'hidden');
input.attr('name', $(this).attr("name")); // Same name as the checkbox
input.attr('value', "no"); // or 'off', 'false', 'no', whatever
// append it to the form the checkbox is in just as it's being submitted
formEl.append(input); //$("#foo") is referring to the form
} // end function inside each()
); // end each() argument list
return true; // Don't abort the form submit
} // end function inside submit()
);