JavaScript Submithandler Issue

2019-07-11 04:07发布

 $("#myform").validate({
        submitHandler: function (form) {
            var cboxes = ($('input:checkbox:checked').filter(":checked").length);
            var nboxes = ($(":checkbox:not(:checked)").length);
            var flag = false;
            if ((cboxes > 0) && (nboxes > 0)) {
                flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? ');
            } else if (cboxes == 0) {
                alert('Please select atleast One Address \n Where you would prefer to prescribe from.');
            }
            else {
                flag = true;
            }
            return flag;
        }
    });

When the Confirm box pop up if I clicks ok it should accept the submit, but it is not.

Can anyone tell me why is this happening?

1条回答
做个烂人
2楼-- · 2019-07-11 04:58

Replace return flag with form.submit.

$("#myform").validate({
    submitHandler: function (form) {
        var cboxes = ($('input:checkbox:checked').filter(":checked").length);
        var nboxes = ($(":checkbox:not(:checked)").length);
        var flag = false;
        if ((cboxes > 0) && (nboxes > 0)) {
            flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? ');
        } else if (cboxes == 0) {
            alert('Please select atleast One Address \n Where you would prefer to prescribe from.');
        }
        else {
            flag = true;
        }

        if(flag)
            form.submit();
    }
});

If you're not using AJAX, this is the way described in the .validate() docs.

查看更多
登录 后发表回答