2 of 2
Nihathrael
• 631
• 4
• 12

I came up with this somewhat shorter solution.

Using an array to find out if one of the checkboxes has not been clicked is unnecessary here, as you are only interested in if all checkboxes are clicked or not. That leads to two possible solutions, one is using a booling to saving the state using a normal for loop or using an early return to break from the loop in case a checkbox that has not been clicked is found. I decided to go with the early return as it shortens the method and removes the need for the if/else construct at the end.

$("#btnSubmitToCheckOut").click(function(event) { var checkBoxes =$(".age_agree :checkbox")

for(int i=0; i < checkBoxes.length; i++) {
if (!checkBoxes[i].is(":checked")) {
return;
}
};

\$(this).parents('form').submit();
});


What do you think?

Nihathrael
• 631
• 4
• 12