mercredi 19 mai 2021

Checkbox and Hidden both passing value even if checkbox is checked or not

I have a following code which I am using to pass value from check box.

echo "<input type='hidden' name='cash[]' value='Non Cash' />";
echo "<td><input type= 'checkbox' name = 'cash[]' value='Cash'/></td>"; 

But when I submit the form, value from hidden type pass through even if I check checkbox or no. For example, if I check checkbox like below, cash array will contains value from hidden type as well from checked checkbox too.

image of checked checkbox in a html form

array showing data from both hidden and checkbox

So, is there anyway I can avoid value from hidden type if checkbox is checked in cash array?

Thank you very much is advance.




Aucun commentaire:

Enregistrer un commentaire