It’s time for me to solve the mystery of HTML unchecked checkbox values. I guess it would be the most searched trick about basic HTML forms and checkboxes. When you use checkboxes on our website, you save some values to the checkboxes. But how do you save the unchecked value to it?
I had a same problem when I was working on a recent project of mine, but I searched and found a great solution of this problem. The solution is to insert a hidden form input field with the same name as our checkbox and put the default value right before the place where the checkbox is located in our form:
<input type="hidden" name="box1" value="0" /> <input type="checkbox" name="box1" value="1" />Code language: HTML, XML (xml)
When the checkbox is left unchecked by the user, the hidden field’s value gets submitted. Otherwise, the value of the checked box will be sent.
I hope this tutorial has been helpful to you.