0

The fields in my form already validate. If they're invalid, there's a span class that appears and informs the user. Likewise if they're empty.

So I thought it would be easy enough to just check for the visibility of one of these classes.

Here's my script:

$(document).ready(function(){
  if (($('.error').length) || ($('.empty').length)) {

      function validateReview(){

               document.getElementById('ReviewForm').submit();
      }

  } else {

      function validateReview(){

                alert("Please check fields and be sure to leave a review.");
      }

  }
};

And then the submit button in my form simply calls validateReview() onclick.

But it's not working how I expected, I get this as an error "validateReview is not defined". Did I declare validateReview() incorrectly, or in a local scope maybe? BIG newb here so please be aware. I know enough only to get in trouble.

4

1 回答 1

1

不确定您的逻辑,但我认为您可以使用它

$(document).ready(function(){
    if ($('.error').length || $('.empty').length) {
        $('#ReviewForm')[0].submit();
    } else {
        alert("Please check fields and be sure to leave a review.");
    }
});
于 2012-07-04T21:50:01.793 回答