방법1) =========================================================================================
2번째, 3번째, 4번째 텍스트박스에 숫자 입력하면 1번째 텍스트박스에 자동합계 나오는 스크립트
<script language='javascript'>
function sum(){
var f1_1 = document.getElementById('f1_1');
var f1_2 = document.getElementById('f1_2');
var f1_3 = document.getElementById('f1_3');
var f1_4 = document.getElementById('f1_4');
f1_1.value = Number(f1_2.value)+Number(f1_3.value)+Number(f1_4.value);
}
</script>
<INPUT name=f1_1 id=f1_1>
<INPUT name=f1_2 id=f1_2 onkeyup="sum();">
<INPUT name=f1_3 id=f1_3 onkeyup="sum();">
<INPUT name=f1_4 id=f1_4 onkeyup="sum();">
방법 2) =========================================================================================
첫번째, 두번째 텍스트박스에 값 입력하면 세번째 텍스트박스에 바로 계산되네요.
<script language="javascript">
<!--
function Chking() {
var f = eval("document.frm");
if(f.a.value && f.b.value) {
f.all.value = parseInt(f.a.value) + parseInt(f.b.value);
} else {
return false;
}
}
//-->
</script>
<form name="frm" method="POST">
<input type="text" name="a" onKeyPress="Chking();" onKeyUp="Chking();">
<br>
<input type="text" name="b" onKeyPress="Chking();" onKeyUp="Chking();">
<br>
<br>
<input type="text" name="all">
</form>
방법 3) =========================================================================================
<form name="sumfrm" method="post" action="">
숫자1 : <input type="text" name="qty" onBlur="sum()">
숫자2 : <input type="text" name="qty" onBlur="sum()">
숫자3 : <input type="text" name="qty" onBlur="sum()">
결과 : <input type="text" name="sum_qty">
</form>
<script language=javascript>
<!--
function sum()
{
var obj = document.sumfrm;
var sum=0;
for(i=0;i<obj.qty.length;i++)
{
if(obj.qty[i].value*0 == 0)
{
sum += obj.qty[i].value*1;
}
}
obj.sum_qty.value = sum;
}
//-->
</script>