Hi i have this select dropdown time. Now i want that when i unchecked the selected one it will return a value on it using hidden textbox. Now my problem is when the checkbox is not unchecked the form value of a hidden input field will be passed also. I want that when i did not unchecked the checkbox the hidden value will not passed. I know that the behaviour of a checkbox when unchecked returns empty. This is my first time trying to achieved this thing. Here is my code below
<input type="hidden" name="checkbox-tuesday[]" value="00:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-1-tuesday" value="00:00" <?php echo (isset($tuesdaysArray[0]) == "00:00" ? 'checked' : '');?>> 00:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="1:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-2-tuesday" value="1:00" <?php echo (isset($tuesdaysArray[1]) == "1:00" ? 'checked' : '');?>> 1:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="2:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-3-tuesday" value="2:00" <?php echo (isset($tuesdaysArray[2]) == "2:00" ? 'checked' : '');?>> 2:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="3:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-4-tuesday" value="3:00" <?php echo (isset($tuesdaysArray[3]) == "3:00" ? 'checked' : '');?>> 3:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="4:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-5-tuesday" value="4:00" <?php echo (isset($tuesdaysArray[4]) == "4:00" ? 'checked' : '');?>> 4:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="5:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-6-tuesday" value="5:00" <?php echo (isset($tuesdaysArray[5]) == "5:00" ? 'checked' : '');?>> 5:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="6:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-7-tuesday" value="6:00" <?php echo (isset($tuesdaysArray[6]) == "6:00" ? 'checked' : '');?>> 6:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="7:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-8-tuesday" value="7:00" <?php echo (isset($tuesdaysArray[7]) == "7:00" ? 'checked' : '');?>> 7:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="8:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-9-tuesday" value="8:00" <?php echo (isset($tuesdaysArray[8]) == "8:00" ? 'checked' : '');?>> 8:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="9:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-10-tuesday" value="9:00" <?php echo (isset($tuesdaysArray[9]) == "9:00" ? 'checked' : '');?>> 9:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="10:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-11-tuesday" value="10:00" <?php echo (isset($tuesdaysArray[10]) == "10:00" ? 'checked' : '');?>> 10:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="11:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-12-tuesday" value="11:00" <?php echo (isset($tuesdaysArray[11]) == "11:00" ? 'checked' : '');?>> 11:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="12:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-13-tuesday" value="12:00" <?php echo (isset($tuesdaysArray[12]) == "12:00" ? 'checked' : '');?>> 12:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="13:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-14-tuesday" value="13:00" <?php echo (isset($tuesdaysArray[13]) == "13:00" ? 'checked' : '');?>> 13:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="14:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-15-tuesday" value="14:00" <?php echo (isset($tuesdaysArray[14]) == "14:00" ? 'checked' : '');?>> 14:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="15:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-16-tuesday" value="15:00" <?php echo (isset($tuesdaysArray[15]) == "15:00" ? 'checked' : '');?>> 15:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="16:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-17-tuesday" value="16:00" <?php echo (isset($tuesdaysArray[16]) == "16:00" ? 'checked' : '');?>> 16:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="17:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-18-tuesday" value="17:00" <?php echo (isset($tuesdaysArray[17]) == "17:00" ? 'checked' : '');?>> 17:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="18:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-19-tuesday" value="18:00" <?php echo (isset($tuesdaysArray[18]) == "18:00" ? 'checked' : '');?>> 18:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="19:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-20-tuesday" value="19:00" <?php echo (isset($tuesdaysArray[19]) == "19:00" ? 'checked' : '');?>> 19:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="20:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-21-tuesday" value="20:00" <?php echo (isset($tuesdaysArray[20]) == "20:00" ? 'checked' : '');?>> 20:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="21:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-22-tuesday" value="21:00" <?php echo (isset($tuesdaysArray[21]) == "21:00" ? 'checked' : '');?>> 21:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="22:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-23-tuesday" value="22:00" <?php echo (isset($tuesdaysArray[22]) == "22:00" ? 'checked' : '');?>> 22:00 <br>
<input type="hidden" name="checkbox-tuesday[]" value="23:00-blocked" />
<input type="checkbox" name="checkbox-tuesday[]" id="checkbox-24-tuesday" value="23:00" <?php echo (isset($tuesdaysArray[23]) == "23:00" ? 'checked' : '');?>> 23:00 <br>
My backend script. Now this is the result if i click submit to my form
Array
(
[0] => 00:00-blocked
[1] => 00:00
[2] => 1:00-blocked
[3] => 1:00
[4] => 2:00-blocked
[5] => 2:00
[6] => 3:00-blocked
[7] => 3:00
[8] => 4:00-blocked
[9] => 4:00
[10] => 5:00-blocked
[11] => 5:00
[12] => 6:00-blocked
[13] => 6:00
[14] => 7:00-blocked
[15] => 7:00
[16] => 8:00-blocked
[17] => 8:00
[18] => 9:00-blocked
[19] => 9:00
[20] => 10:00-blocked
[21] => 10:00
[22] => 11:00-blocked
[23] => 11:00
[24] => 12:00-blocked
[25] => 12:00
[26] => 13:00-blocked
[27] => 13:00
[28] => 14:00-blocked
[29] => 14:00
[30] => 15:00-blocked
[31] => 15:00
[32] => 16:00-blocked
[33] => 16:00
[34] => 17:00-blocked
[35] => 17:00
[36] => 18:00-blocked
[37] => 18:00
[38] => 19:00-blocked
[39] => 19:00
[40] => 20:00-blocked
[41] => 20:00
[42] => 21:00-blocked
[43] => 21:00
[44] => 22:00-blocked
[45] => 22:00
[46] => 23:00-blocked
[47] => 23:00
)
the hidden data is being passed. I want that when i unchecked the checkbox the data hidden will only display. How can i able to avoid this thing? Any help is muchly appreciated. TIA
Aucun commentaire:
Enregistrer un commentaire