Exit not only from child function but from whole parent function

Add a flag that has to be false to continue.

function validate() {
    var invalid = false;
    $('.var_txt').each(function() {
        if ($.trim($(this).val()) == '') {
            $(this).focus();
            invalid = true;
            return false;
        }
    });
    if (invalid) {
        return false;
    }

    if (!$(".answer:checked").val()) {
        alert("boom");
        return false;
    }
    return true;
}
$(document).ready(function() {
    $("#add_question").submit(function(e) {
        if (validate()) {
            alert("good");
        }
        e.preventDefault();
    })

});​

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)