ช่วยดูโค้ดหน่อยค่ะ ว่าต้องเพิ่มเงื่อนไขตรงไหนหรือเปล่าค่ะ
โค้ด php
ไม่คำนวณค่า Total ให้ค่ะเวลากดปุ่ม ต้องเพิ่มเงือนไขตรงไหนหรือเปล่าค่ะ
<script language="javascript">
function fncCal()
{
var tot = 0;
var sum = 0;
for(i=1;i<=document.form1.hdnLine.value;i++)
{
tot = parseFloat(eval("document.form1.txtPCS1_"+i+".value")) * parseFloat(eval("document.form1.txtSALES1_"+i+".value"))
if (isNaN(tot)) tot = 0;
eval("document.form1.txtSUM1_"+i+".value="+tot);
sum = tot;
}
document.form1.txtSUMTOTAL.value=sum;
}</script>
</head>
<body>
<form action="page.cgi" method="post" name="form1">
<table width="1141" border="1" align="center">
<tr bordercolor="#FF0000" bgcolor="#555555" class="style2">
<td width="76"><div align="center">
<span class="style4">ITEM NO</span></td>
<td width="167"> <div align="center">
<span class="style4">ITEM NAME</span></td>
<td width="192"><div align="center">
<span class="style4">SPEC</span></td>
<td width="167"><div align="center">
<span class="style4">SIZE</span></td>
<td width="180"><div align="center">
<span class="style4">PCS</span></td>
<td width="128"><div align="center">
<span class="style4">CURR</span></td>
<td width="119"><div align="center">
<span class="style4">UNITPRICE</span></td>
<td width="60"><div align="center">
<span class="style4">SUM TOTAL</span></td>
</tr>
<tr>
<td><lable>
<div align="center">
<input type="text" name="txtITEM_NO1" id="txtITEM_NO1" size="5" OnChange="JavaScript:doCallAjax('txtITEM_NO1','txtITEM_NAME1','txtSPEC1','txtSIZE1','txtCURR1','txtSALES1_1');">
</div></th>
<th><input type="text" name="txtITEM_NAME1" id="txtITEM_NAME1" size="10"></th>
<th><input type="text" name="txtSPEC1" id="txtSPEC1" size="10"></th>
<th><input type="text" name="txtSIZE1" id="txtSIZE1" size="10"></th>
<th><input type="text" name="txtPCS1[]" id="txtPCS1_1" size="5" ></th>
<th><input type="text" name="txtCURR1" id="txtCURR1" size="5"></th>
<th><input type="text" name="txtSALES1[]" id="txtSALES1_1" size="10"></th>
<th><input type="text" name="txtSUM1[]" id="txtSUM1_1" size="10" ></th>
</tr>
<tr>
<th>
<div align="center">
<input type="text" name="txtITEM_NO2" id="txtITEM_NO2" size="5" OnChange="JavaScript:doCallAjax('txtITEM_NO2','txtITEM_NAME2','txtSPEC2','txtSIZE2','txtCURR2','txtSALES1_2');">
</div></th>
<th><input type="text" name="txtITEM_NAME2" id="txtITEM_NAME2" size="10"></th>
<th><input type="text" name="txtSPEC2" id="txtSPEC2" size="10"></th>
<th><input type="text" name="txtSIZE2" id="txtSIZE2" size="10"></th>
<th><input type="text" name="txtPCS1[]" id="txtPCS1_2" size="5"></th>
<th><input type="text" name="txtCURR2" id="txtCURR2" size="5"></th>
<th><input type="text" name="txtSALES1[]" id="txtSALES1_2" size="10"></th>
<th><input type="text" name="txtSUM1[]" id="txtSUM1_2" size="10"></th>
</tr>
<input type="hidden" name="hdnLine" value="5">
<tr>
<th>
<div align="center">
</div></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Total</th>
<th><input type="text" name="txtSUMTOTAL" id="txtSUMTOTAL" size="10"></th>
<th> <input name="btnCal" type="button" value="Cal" OnClick="JavaScript:fncCal();"></th>
</tr>
</table>Tag : PHP, MySQL, JavaScript, Ajax
Date :
2010-11-16 13:52:55
By :
taewengja
View :
645
Reply :
3
<script language="javascript">
function fncCal()
{
var tot = 0;
var sum = 0;
for(i=1;i<=document.form1.hdnLine.value;i++)
{
tot = parseFloat(eval("document.form1.txtPCS1_"+i+".value")) * parseFloat(eval("document.form1.txtSALES1_"+i+".value"))
if (isNaN(tot)) tot = 0;
eval("document.form1.txtSUM1_"+i+".value="+tot);
sum += tot;
}
document.form1.txtSUMTOTAL.value=sum;
}</script>
</head>
<body>
<form action="page.cgi" method="post" name="form1">
<table width="1141" border="1" align="center">
<tr bordercolor="#FF0000" bgcolor="#555555" class="style2">
<td width="76"><div align="center">
<span class="style4">ITEM NO</span></td>
<td width="167"> <div align="center">
<span class="style4">ITEM NAME</span></td>
<td width="192"><div align="center">
<span class="style4">SPEC</span></td>
<td width="167"><div align="center">
<span class="style4">SIZE</span></td>
<td width="180"><div align="center">
<span class="style4">PCS</span></td>
<td width="128"><div align="center">
<span class="style4">CURR</span></td>
<td width="119"><div align="center">
<span class="style4">UNITPRICE</span></td>
<td width="60"><div align="center">
<span class="style4">SUM TOTAL</span></td>
</tr>
<tr>
<td><lable>
<div align="center">
<input type="text" name="txtITEM_NO1" id="txtITEM_NO1" size="5" OnChange="JavaScript:doCallAjax('txtITEM_NO1','txtITEM_NAME1','txtSPEC1','txtSIZE1','txtCURR1','txtSALES1_1');">
</div></th>
<th><input type="text" name="txtITEM_NAME1" id="txtITEM_NAME1" size="10"></th>
<th><input type="text" name="txtSPEC1" id="txtSPEC1" size="10"></th>
<th><input type="text" name="txtSIZE1" id="txtSIZE1" size="10"></th>
<th><input type="text" name="txtPCS1[]" id="txtPCS1_1" size="5" ></th>
<th><input type="text" name="txtCURR1" id="txtCURR1" size="5"></th>
<th><input type="text" name="txtSALES1[]" id="txtSALES1_1" size="10"></th>
<th><input type="text" name="txtSUM1[]" id="txtSUM1_1" size="10" ></th>
</tr>
<tr>
<th>
<div align="center">
<input type="text" name="txtITEM_NO2" id="txtITEM_NO2" size="5" OnChange="JavaScript:doCallAjax('txtITEM_NO2','txtITEM_NAME2','txtSPEC2','txtSIZE2','txtCURR2','txtSALES1_2');">
</div></th>
<th><input type="text" name="txtITEM_NAME2" id="txtITEM_NAME2" size="10"></th>
<th><input type="text" name="txtSPEC2" id="txtSPEC2" size="10"></th>
<th><input type="text" name="txtSIZE2" id="txtSIZE2" size="10"></th>
<th><input type="text" name="txtPCS1[]" id="txtPCS1_2" size="5"></th>
<th><input type="text" name="txtCURR2" id="txtCURR2" size="5"></th>
<th><input type="text" name="txtSALES1[]" id="txtSALES1_2" size="10"></th>
<th><input type="text" name="txtSUM1[]" id="txtSUM1_2" size="10"></th>
</tr>
<input type="hidden" name="hdnLine" value="2">
<tr>
<th>
<div align="center">
</div></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Total</th>
<th><input type="text" name="txtSUMTOTAL" id="txtSUMTOTAL" size="10"></th>
<th> <input name="btnCal" type="button" value="Cal" OnClick="JavaScript:fncCal();"></th>
</tr>
</table>
Date :
2010-11-16 13:57:45
By :
num
Load balance : Server 03