When using the jQuery validation plugin, What is the right way to use rules and methods when using .valid(). I previously used to use .validate(), but since I had to keep a button outside the form, I was forced to switch to using .valid(). But now, I don't get those custom error messages like it used to before. How do I get this right?
I suspect, the way I'm using .valid() is wrong. I tried may things, but failed at all of them.
<!DOCTYPE HTML>
<html>
<head>
<title>Test Validation Plugin</title>
<script type="text/javascript" src="/resources/scripts/jq.js"></script>
<script type="text/javascript" src="/resources/scripts/temp.js"></script>
<script type="text/javascript" src="/resources/scripts/validate.js"></script>
<body>
<form id="createAccount">
<input type="text" class="titlea" name="titlea" value="" autocomplete="off">
<label for="titlea" generated="true" class="error titlea" style=""></label>
<br>
<br>
<input type="text" class="titleb" name="titleb" value="" autocomplete="off">
<label for="titleb" generated="true" class="error titleb" style=""></label>
</form>
<br>
<button id="btn">Process</button>
</body>
</html>
jQuery code
$('#btn').click(function() {
rules: {
titlea: {
required: true,
minlength: 5,
maxlength: 24
},
titleb: {
required: true,
minlength: 5,
maxlength: 24
},
},
messages: {
titlea: {
required: 'Please choose a title',
minlength: 'Title A should be at least 5 characters',
maxlength: 'Title A cannot exceed 24 characters'
},
titleb: {
required: 'Please choose a title',
minlength: 'Title B should be at least 5 characters',
maxlength: 'Title B cannot exceed 24 characters'
},
}
('#createAccount').valid() { // Is this where the problem is?
// Submit the form using jQuery ajax
}
});