0

I have a form with radio buttons in them. I loop through the radio button groups to determine if they are all checked. If not, I am not submitting the form, otherwise submit the form.

The issue is when it fails the first time, going back and selecting all radios, resubmitting doesnt submit the form. Although I added alerts in there, it is hitting the submit part but not actually submitting.

$('#submit-fee').click(function(){
    var bValid = false;
    $('input[type="radio"]').each(function(index) {
        if($('input[name="'+$(this).attr('name')+'"]:checked').val() == "YES" || $('input[name="'+$(this).attr('name')+'"]:checked').val() == "NO"){
            bValid = true;
        }else{
            bValid = false;
            return false;
        }
    });
    if(!bValid){
        alert("Please make sure all questions are answered.");
        $('#rec-fee-form').submit(function () { 
            return false; 
        }); 
    }else{
        return true;
    }
});
4

1 回答 1

0

尝试这个 -

$('#rec-fee-form').submit(function(){
    var bValid = false;
    $('input[type="radio"]').each(function(index) {
        if($('input[name="'+$(this).attr('name')+'"]:checked').val() == "YES" || $('input[name="'+$(this).attr('name')+'"]:checked').val() == "NO"){
            bValid = true;
        }else{
            bValid = false;
        }
    });
    if(!bValid){
        alert("Please make sure all questions are answered.");
        return false;
    }else{
        return true;
    }
});
于 2013-06-13T15:44:41.557 回答