I'm trying to learn / understand client-side validation with jquery.validate. Currently, I have a basic form defined as shown here:
<form id="myform">
<input id="firstNameTextBox" type="text" />
<input id="lastNameTextBox" type="text" />
<input type="button" value="Test" onclick="return testButtonClick();" />
</form>
<script type="text/javascript">
$(document).ready(function () {
$("#addPersonForm").validate({
rules: {
firstNameTextBox: "required",
lastNameTextBox: "required"
},
messages: {
firstNameTextBox: "Please enter the first name.",
lastNameTextBox: "Please enter the last name."
}
});
});
function testButtonClick() {
string errorMessage = validateFormAndGetMessage();
alert(errorMessage);
return false;
}
</script>
When someone clicks the "Test" button, I want to determine if the form is valid. If it is invalid, I want to display the message associated with the offending rule. How do I do this?