I have an issue with the jquery validate plugin that doesn't make sense to me. Please can anyone see where my mistake is?
Here is my HTML:
<form id="form">
<input type="text" name="name" class="required" />
<input type="text" name="email" class="required email" />
</form>
<a id="link">Save</a>
Here is my JS
<script src="jquery 1.7.1"></script>
<script src="jquery.validate.1.9"></script>
<script>
$('#link').click(function()
{
$('#form').validate();
if ($('#form').valid()) // check if form is valid
{
// do some stuff
}
else
{
// just show validation errors, dont post
}
});
</script>
The form never gets validated or at least the .valid()
function always returns true but I can't see why? I used the validate plugin for years but not in this context.
.validate() method needs to be called once on page load to initialize the plugin _before_ you can use the
.valid()` method. In other words, pull.validate()
out of theclick
handler.