Input value :
<input id="KWSP" name="KWSP" size="13" maxlength="13" class="validate[custom[jumlah]] upper" onblur="func(this.id)" onkeyup="calc();" value="<?php echo $reg_row['KWSP'];?>" /> (sebulan)
<input id="Perkeso" name="Perkeso" size="13" maxlength="13" class="validate[custom[jumlah]] upper" onblur="func(this.id)" onkeyup="calc();" value="<?php echo $reg_row['Perkeso'];?>" /> (sebulan)
Output value ( auto calculate ) :
<input id="Caruman" name="Caruman" size="13" maxlength="13" class="validate[custom[jumlah]] upper" value="<?php echo number_format($reg_row['JumCaruman'],2);?>" readonly="readonly"/> (sebulan)
Function :
function calc() {
var KWSP = parseFloat(document.getElementById("KWSP").value);
var Perkeso = parseFloat(document.getElementById("Perkeso").value);
var a = KWSP + Perkeso;
if (a.toFixed(2)!='NaN') { document.getElementById("Caruman").value = a.toFixed(2); }
else { document.getElementById("Caruman").value = ''; }
}
function func(id) {
var field_id = document.getElementById(id);
var num = parseFloat(field_id.value);
if (field_id.value == '') { field_id.value = '0.00'; }
else { field_id.value = num.toFixed(2); }
}
Thursday, 26 September 2013
Auto Calculate
11:58 am
No comments
posted by : Che Wahida
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment