<script language="javascript">
function fncCal()
{
var tot = 0;
var sum = 0;
for(i=0;i<=document.form1.hdnLine.value;i++)
{
tot = parseInt(eval("document.form1.txtVol1_"+i+".value")) * parseInt(eval("document.form1.txtVol2_"+i+".value"))
eval("document.form1.txtVol3_"+i+".value="+tot);
sum = tot + sum;
document.form1.txtSum.value=sum;
}
}
</script>
for($i=0;$i<$cnt;$i++){
$sql3=mysql_query("SELECT price_unit FROM stock WHERE mat_id='$id[$i]'");
list($pu)=mysql_fetch_row($sql3);
$sql=mysql_query("SELECT mat_unit_name FROM unit WHERE mat_unit_id='$u[$i]'");
list($unit)=mysql_fetch_row($sql);
$sql2=mysql_query("SELECT mat_type_name FROM type WHERE mat_type_id='$t[$i]'");
list($type)=mysql_fetch_row($sql2);
echo "<tr><td align='center'><input type='checkbox' name='cancel_id[]' value='",$id[$i],"'></td>";
echo "<td align='center'>",$id[$i],"</td>";
echo "<td align='center'>",$_SESSION['smat_name'][$i],"</td>";
echo "<td align='center'>",$_SESSION['smat_stock'][$i],"</td>";
echo "<td align='center'>",$unit,"</td>";
echo "<td align='center'>",$type,"</td>";
echo " <td><input name='price_unit[]' id='txtVol1_$i' value='$pu' OnChange='JavaScript:fncCal();' type='text'> </td>
<td><input name='amount[]' id='txtVol2_$i' OnChange='JavaScript:fncCal();' type='text'></td>
<td><input name='sum[]' id='txtVol3_$i' type='text'><br></td></tr>";
echo "<input type='hidden' name='hdnLine' value='$cnt'>";
}
Code (JavaScript)
function fncCal()
{
var tot = 0;
var sum = 0;
for(i=0;i<=document.form1.hdnLine.value;i++)
{
tot = parseInt(eval("document.form1.txtVol1_"+i+".value")) * parseInt(eval("document.form1.txtVol2_"+i+".value"))
eval("document.form1.txtVol3_"+i+".value="+tot);
sum = tot + sum;
document.form1.txtSum.value=sum;
}
}