Javascript: Calculate balance and advance through text field input -
i beginner javascript. have code through user enters value through input field ('to enter given fees'). want is, if user types more '1000', advance value should come in input text('advance fee').
if user types less '1000', balance amount should come in text input ('balance fees').
my fiddle carries way worked in.
my html form :
<form> <div class="tbl_admission_formcell">given fees</div> <div class="tbl_admission_formcell" style="padding:10px;"><input type="text" name="given_fees" value="" id="given_fees" onkeypress="givenfees()" onkeyup="givenfees()"/> </div> <div class="tbl_admission_formcell">balance fees</div> <div class="tbl_admission_formcell"><span id="balance_fees"></span> </div> <div class="tbl_admission_formcell">advance fees</div> <div class="tbl_admission_formcell"><span id="advance_fees"></span> </div> <div class="tbl_admission_formrow"> <div class="tbl_admission_formcell">total fees</div> <div class="tbl_admission_formcell"><input type="text" id="total_fees" name="total_fees" style="border:none;" value="1000" readonly/></div> <div class="tbl_admission_formcell"><div class="amt_total" onchange="amt_total()" ></div></div> </div> </form> <script> function givenfees(){ var given_fees = document.getelementbyid("given_fees"); var s = given_fees.value; bal_value = +s - +result; var balance_fees = document.getelementbyid("balance_fees"); if(+bal_value<0 ) { advance_fees.innertext = +bal_value; } else {balance_fees.innertext = +bal_value;} } </script>
i have edited answer. please check fiddle. hope if understand problem exactly.
function givenfees(){ var result=1000; var given_fees = document.getelementbyid("given_fees"); var s = given_fees.value; bal_value = +s - +result; var balance_fees = document.getelementbyid("balance_fees"); if(+bal_value>0 ) { advance_fees.innertext = +bal_value; balance_fees.innertext = 0; } else { balance_fees.innertext = +bal_value; advance_fees.innertext = 0; } }
Comments
Post a Comment