I am creating an ASP.NET MVC 5 application. I need to write some jQuery or JavaScript that checks if the application's form is valid (using jQuery Validate) when the form is submitted. If the form is valid, then the form needs to simultaneously submit and show an alert box (for now). I have used this post so far to sculpt my code, but it is not working for me. This code is functioning correctly:
$('form').submit(function () {
alert('test');
});
But this does not work for me:
$('form').submit(function () {
if ($(this).valid()) {
alert('the form is valid');
}
});
I am getting the following error:
Uncaught TypeError: $(...).valid is not a function
I don't understand why this code worked for other people but it does not work for me. Where am I going wrong?
How can I get the submit button to simultaneously show the alert box and submit the form when the form is valid?