<html>
<head>
<title></title>
</head>
<SCRIPT Language="JavaScript">
//function คำนวณผลรวม
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
	one = parseFloat(document.enpi.f_gen2_1_1.value.replace(/,/g, ''));
	two = parseFloat(document.enpi.f_gen2_1_2.value.replace(/,/g, ''));
	f_gen2 = parseFloat(document.enpi.f_gen2.value.replace(/,/g, ''));

	result = (one * 1) + (two * 1);
	if (isNaN(result )) {
		document.enpi.f_gen2.value = "ไม่ได้";
	}
	else {
		document.enpi.f_gen2.value = result.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	}

	result3 = (two * 1) + (f_gen2 * 1);
	if (isNaN(result3 )) {
		document.enpi.f_gen3.value = "ไม่ได้";
	}
	else {
		document.enpi.f_gen3.value = result3.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
	}

}
function stopCalc(){
clearInterval(interval);
}
</SCRIPT>

<script type="text/javascript">
//function ใส่จุด Comma ของตัวเลข
function Commas(str)
{
var parts = str.toString().replace("," ,"").split(".");
parts[0] = parts[0].replace("," ,"").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
</script>

<form name="enpi" form method="post" action="qa2mail-hotel.php">
<input name="f_gen2_1_1" type="text" class="fill_in" onchange="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right" onkeyup="this.value = Commas(this.value)" onKeyPress="return bannedKey(event,this.value)"/> A<br />
<input name="f_gen2_1_2" type="text" class="fill_in" onchange="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right"  onKeyPress="return bannedKey(event,this.value)"/> B<br />
<input name="f_gen2" type=text class="right" onchange="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right"  onKeyPress="return bannedKey(event,this.value)" style="text-align: right" />
<input name="f_gen3" type=text class="right" onchange="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right" onkeyup="this.value = Commas(this.value)" onKeyPress="return bannedKey(event,this.value)" style="text-align: right" />

Sum<br />
</form>
</body>
</html>
