0

I want to use $.each inside a function. But i have problems with the return value, which should be overwritten in the each function.

function validate_voting_stars() {
    $error = false;
    $.each( $('input.rr'), function(index,value){
        vote = $(this).val();
        if( $.isNumeric($(this).val() ) && vote < 6 ) {
            return;
        } else {
            $error = true;
        }
    })
    return $error;
}

I think, that the firing of the return value is not waiting for finishing the each function of jQuery. Is there a way, how i can solve this? For testing i added the return inside the each function, but this is not working too

Any ideas?

2
  • do you want to return false if any one of the input is invalid Commented Apr 27, 2013 at 11:15
  • Yes. If one of the input ".rr" is empty or not_numeric... Commented Apr 27, 2013 at 11:17

1 Answer 1

1

Try

function validate_voting_stars() {
    $error = false;
    $.each( $('input.rr'), function(index,value){
        vote = $(this).val();
        if( !$.isNumeric($(this).val() ) || vote > 6 ) {
            $error = true;
            return false;
        }
    })
    return $error;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.