javascript - Percentage calculation error -
i trying calculate percentage of number (taken 1 text field) , set calculated value form field. have tried below code observing mismatch in key event/decimal places js detecting.
for example if provide 100 in first input field (to calculate percentage of 1.75), based on js code expect 1.75 in second text field coming 0.175. know simple calculation unable solve this.
var refee = document.getelementbyid("estimated referral fee"); var lnamt = document.getelementbyid("loan amount"); refee.disabled = true; lnamt.onkeydown = function isnumber(evt) { evt = (evt) ? evt : window.event; var charcode = (evt.which) ? evt.which : evt.keycode; if (charcode > 31 && (charcode < 48 || charcode > 57)) { return false; } calcper(lnamt.value); } function calcper(amtval) { var pernum = 1.75; refee.value = (pernum / 100) * amtval; }
<div class="form-group"> <label class="control-label col-sm-2">loan amount</label> <div class="col-sm-10"> <input id="loan amount" placeholder="provide loan amount" data-toggle="tooltip" data-original-title="provide loan amount" required="required" class="form-control" name="loan amount" type="text" value=""> <span class="help-block"></span> </div> </div> <div class="form-group"> <label class="control-label col-sm-2">estimated referral fee</label> <div class="col-sm-10"> <input id="estimated referral fee" placeholder="your referral fee" data-toggle="tooltip" data-original-title="your referral fee" required="required" class="form-control" name="estimated referral fee" type="text" value="" disabled=""> <span class="help-block"></span> </div> </div>
var refee = document.getelementbyid("estimated referral fee"); var lnamt = document.getelementbyid("loan amount"); refee.disabled = true; lnamt.onkeyup = function isnumber(evt) { evt = (evt) ? evt : window.event; var charcode = (evt.which) ? evt.which : evt.keycode; if (charcode > 31 && (charcode < 48 || charcode > 57)) { return false; } calcper(lnamt.value); } function calcper(amtval) { var pernum = 1.75; refee.value = (pernum / 100) * amtval; }
<div class="form-group"> <label class="control-label col-sm-2">loan amount</label> <div class="col-sm-10"> <input id="loan amount" placeholder="provide loan amount" data-toggle="tooltip" data-original-title="provide loan amount" required="required" class="form-control" name="loan amount" type="text" value=""> <span class="help-block"></span> </div> </div> <div class="form-group"> <label class="control-label col-sm-2">estimated referral fee</label> <div class="col-sm-10"> <input id="estimated referral fee" placeholder="your referral fee" data-toggle="tooltip" data-original-title="your referral fee" required="required" class="form-control" name="estimated referral fee" type="text" value="" disabled=""> <span class="help-block"></span> </div> </div>
Comments
Post a Comment