I have developed a 3 state checkbox that allows me to send 3 different values. Here are the values that I have set for a checkbox.
State 0 [] = Uncheck (Value = 0)
State 1 [x] = Checked (Value = 1)
State 2 [-] = Indeterminate (Value = 2)
Now the problem lays when sending the values via POST method. Since Uncheck and Indeterminate are unselected, the values don't get sent and I get a value of 0 on the database on both state 0 or state 2.
This is the logic script for the checkboxes:
<script>
window.onload = function ()
{
setCheckBoxes(document.getElementById('LEVL1LES1'));
}
function setCheckBoxes(cb) {
if (cb.value == 0)
{
cb.checked = false;
}
else if (cb.value == 1)
{
cb.checked = true;
}
else
{
cb.indeterminate=true;
}
}
function changeBoxValues(cb) {
if (cb.value == 0)
{
cb.value = 1;
setCheckBoxes(cb);
}
else if (cb.value == 1)
{
cb.value = 2;
setCheckBoxes(cb);
}
else
{
cb.value = 0;
setCheckBoxes(cb);
}
}
And HTML:
<input type="checkbox" name="LEVL1LES1" value='<?php echo $row["LEVL1LES1"]?>' id="LEVL1LES1" onclick="changeBoxValues(this)">
Can anyone give me any input on how to fix this problem since I know that I am trying to make a workaround the default behavior oh checkboxes?
PS. You may ask why I don't use other options like dropdown? Here is why: