I have a set of flags that, when validated, pass the value as 1, otherwise they pass the value equal to 0. However, instead of sending the value of the unchecked flags as "0", the value sent is equal to "NULL.
I have the following JS code, which should set the value to 0/1 respectively, however still the value is sent as NULL. Is there anything that can be done to make sure that the value passed in the case of an unchecked flag is 0?
$('#cb1, #cb2, #cb3, #cb4').on('click', function () $(this).val(this.checked ? 1 : 0); });
UPDATED Here is my html:
<input type="checkbox" name="cb1" id="cb1" value="1" checked /> <input type="checkbox" name="cb2" id="cb2" value="1" checked /> <input type="checkbox" name="cb3" id="cb3" value="1" checked /> <input type="checkbox" name="cb4" id="cb4" value="1" checked />
All of them are marked by default.
If one of them is not installed, MySQL reports an error: 0SQLSTATE [23000]: Violation of integrity constraint: 1048 Column "ColumnName" cannot be zero.
This is because the columns are set to non-Null. And although I set the default value to 0, as soon as I press the submit button, I still get the error. I tried to remove the Not NULL property, but instead of pre-populating the value as 0, the database was NULL.
user1809790
source share