Skip to content

How To Set Value Of Unchecked Checkbox

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.

3 thoughts on “How To Set Value Of Unchecked Checkbox”

  1. Sorry, but by using this code it results in [ ‘0’, ‘1’ ] value when the checkbox is checked .. Is there a way that i missunderstood what you did ?

Leave a Reply

Your email address will not be published. Required fields are marked *