Notice removed Needs detailed answers by 200_success
Add some explainations.
Source Link
Nihathrael
  • 621
  • 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")) {
           alert('Please accept all the Terms and Conditions');
           return;
        }
    };

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

What do you think?

I came up with this somewhat shorter solution.

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

    for(int i=0; i < checkBoxes.length; i++) {
        if (!checkBoxes[i].is(":checked")) {
           alert('Please accept all the Terms and Conditions');
           return;
        }
    };

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

What do you think?

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")) {
           alert('Please accept all the Terms and Conditions');
           return;
        }
    };

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

What do you think?

Notice added Needs detailed answers by Jamal
Source Link
Nihathrael
  • 621
  • 4
  • 12

I came up with this somewhat shorter solution.

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

    for(int i=0; i < checkBoxes.length; i++) {
        if (!checkBoxes[i].is(":checked")) {
           alert('Please accept all the Terms and Conditions');
           return;
        }
    };

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

What do you think?