I'm having some issues writing logic for a script. I can't seem to wrap my head around it.
I have a form that contains 6 quantity fields, and two corresponding check boxes for each quantity field.
Quantity fields are referenced in variables $q1, $q2, $q3, $q4, $q5, $q6
.
Check boxes are referenced in variables $c1_1, $c1_2, $c2_1, $c2_2
... etc.
The logic I want to achieve is, if you input a number into a quantity field, either one of the two corresponding checkboxes must be checked as well or the form invalidates.
My current code looks like this:
if(
($q1 !== "" && ($c1_1 == "" || $c1_2 == "")) ||
($q2 !== "" && ($c2_1 == "" || $c2_2 == "")) ||
($q3 !== "" && ($c3_1 == "" || $c3_2 == "")) ||
($q4 !== "" && ($c4_1 == "" || $c4_2 == "")) ||
($q5 !== "" && ($c5_1 == "" || $c5_2 == "")) ||
($q6 !== "" && ($c6_1 == "" || $c6_2 == ""))
) {
$is_valid = false;
} else {
$is_valid = true;
}
What's wrong with that code is that when I go to test that script, it requires both checkboxes to be checked to validate.