I\'m using the jQuery validation plugin and I want make use of a custom method which takes two the values entered into two different textboxes into account when deciding if
Try the following:
Create the Rule
jQuery.validator.addMethod("checkTotal",function(value) {
total = parseFloat($('#LHSOPERAND').val()) + parseFloat($('#RHSOPERAND').val());
return total == parseFloat($('#TOTAL').val());
}, "Amounts do not add up!");
jQuery.validator.classRuleSettings.checkTotal = { checkTotal: true };
Input
<input type="text" name="TOTAL" id="TOTAL" class="required checkTotal" />
Init Validation
$(document).ready(function() {
$("#TOTALSFORM").validate();
});
Fiddle here: http://jsfiddle.net/wTMv3/