jQuery Form Validation Works Only Once Issue

User must select at least one checkbox option. If valid > submit form. Only works once. If the user will check and uncheck the box, and submit again, the form will submit empty.

$('#submit-button').on('click', function() {
    $('input:checkbox').each(function() {
        if (!$(this).is(":checked")) {
            $('#submit-error').html('Plase select at least one option!');
            return false;
        } else {
            $('#my-form').submit();
        }
    });
});

EDIT: this form is inside a Modal window

Answers 1

  • $('#submit-button').on('click', function() {
        if(!$('input[type="checkbox"]:checked').length)
        {
            $('#submit-error').html('Plase select at least one option!');
            return false;
        }
        else 
           $('#my-form').submit();
    });
    

Related Articles