Monday, June 18, 2012

JQuery Validate multiple fields with one error


----------HTML----------------








--------HTML END--------------

--------- Jquery ---------------

$.validator.addMethod("selectMonth", function (value, element) {
return this.optional(element) || (value.indexOf('-1'));
}, "Please select month");
$.validator.addMethod("selectYear", function (value, element) {
return this.optional(element) || (value.indexOf('-1'));
}, "Please select year");

jQuery(document).ready(function () {
$("#mainForm").validate({
rules: {
<%=ddlPaymentType.UniqueID %>:{selectNone:true},
<%=txtAccountNumber.UniqueID %>:{required:true, digits:true},
<%=txtAmount.UniqueID %>:{required:true,decimalTwo:true},
<%=ddlExpirationMonth.UniqueID %>:{selectMonth:true},
<%=ddlExpirationYear.UniqueID %>:{selectYear:true}
},
groups: {
Expiration: "<%=ddlExpirationMonth.UniqueID %> <%=ddlExpirationYear.UniqueID %>"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "ctl00$ContentSection$ddlExpirationMonth" || element.attr("name") == "ctl00$ContentSection$ddlExpirationYear")
error.insertAfter("#ContentSection_ddlExpirationYear");
else
error.insertAfter(element);
}
});
------------ Jquery End --------------------

No comments:

Post a Comment