JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<form action="#" method="post" id="frmLogin" >
<input type="text" name="text1" id="text1" value="0" />%
<input type="text" name="text2" id="text2" value="0" />%
<input id="submit" type="submit" />
</form>
JavaScript
$(document).ready(function () {
jQuery.validator.addMethod("TotalSum", function (value, element, params) {
total = parseFloat(value) + parseFloat($(params[0]).val());
return total == 100;
}, "Total must add up to 100%!");
$("#frmLogin").validate({
rules: {
text1: {
required: true,
TotalSum: ['#text2']
},
text2: {
required: true,
TotalSum: ['#text1']
}
},
groups: {
percent: "text1 text2"
},
errorPlacement: function (error, element) {
error.insertAfter($('#submit'));
}
});
});