$(document).ready(function() { $('#slctPDistrict').focus(); $('#txtPValue').on('input',function(e){ getPTax(); }); // validate form $("#frmValueRequest").validate({ rules: { }, messages: { }, }); }); $(function() { }); function getPTax() { pval = $("#txtPValue").val(); ptemp = pval.replace(/[^0-9\.]/g, ''); if(!$.isNumeric(ptemp)) { ptemp = ''; } // END if $("#txtPTemp").val(ptemp); pdist = $("#slctPDistrict option:selected").val(); if(!$.isNumeric(pdist)) { pdist = 0; } // END if ptax = ptemp*pdist; ptax = ptax.toFixed(2); pprimary = ptax*0.55; pprimary = pprimary.toFixed(2); pdist = (pdist*100).toFixed(4); pval = addCommas(ptemp); ptax = addCommas(ptax); pprimary = addCommas(pprimary); $("#txtPValue").val('$'+pval); $("#txtPRate").val(pdist+"%"); $("#txtPTax").val('$'+ptax); $("#txtPPrimary").val('$'+pprimary); return false; } // END function getPTax function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } // END function addCommas function ClearForm() { $('#frmValueRequest')[0].reset(); } // END ClearForm