javascript คำนวณ array จำนวนรวม sum ทั้งหมด ไม่แสดง..................................
จะให้ตัวเลขแสดงในช่องสุดท้ายเป็นจำนวนเงินรวมทั้งหมดอ้ะต้ะ แต่มันยังไม่แสดง
script.php
<script language="javascript">
function OpenPopup(intLine)
{
window.open('pop_type.php?Line='+intLine,'myPopup','width=650,height=1000,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
function OpenPopup2(intLine)
{
window.open('pop_color.php?Line='+intLine,'myPopup','width=650,height=600,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
function OpenPop(intLine)
{
window.open('pop_branch.php?Line='+intLine,'myPopup','width=650,height=1000,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
function OpenUp(intLine)
{
window.open('pop_utype.php?Line='+intLine,'myPopup','width=650,height=200,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
}
function textsum(rowId){
var amount = document.getElementById('amount'+rowId).value;
var price = document.getElementById('price'+rowId).value;
var total = amount*price;
document.getElementById('total'+rowId).value = total;
}
function allsum(rowId){
var total = document.getElementById('total'+rowId).value;
var all_total = total+total;
document.getElementById('all_total'+rowId).value = total;
}
function CreateNewRow()
{
var intLine = parseInt(document.frmMain.hdnMaxLine.value);
intLine++;
var theTable = document.getElementById("tbExp");
var newRow = theTable.insertRow(theTable.rows.length)
newRow.id = newRow.uniqueID
var newCell
//*** Column No ***//
newCell = newRow.insertCell(0);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center>"+intLine+"</center>";
//*** Column type_id ***//
newCell = newRow.insertCell(1);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"type_id[]\" SIZE=\"5\" ID=\"type_id"+intLine+"\" OnClick=\"OpenPopup('"+intLine+"')\"></center>";
//*** Column type_name ***//
newCell = newRow.insertCell(2);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"type_name[]\" SIZE=\"15\" ID=\"type_name"+intLine+"\" ></center>";
//*** Column color_name ***//
newCell = newRow.insertCell(3);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"color_name[]\" SIZE=\"8\" ID=\"color_name"+intLine+"\" OnClick=\"OpenPopup2('"+intLine+"')\"></center>";
//*** Column unit ***//
newCell = newRow.insertCell(4);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"unit[]\" SIZE=\"5\" ID=\"unit"+intLine+"\" VALUE=\"คัน\"></center>"
//*** Column amount ***//
newCell = newRow.insertCell(5);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"amount[]\" SIZE=\"5\" ID=\"amount"+intLine+"\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\"></center>";
//*** Column price ***//
newCell = newRow.insertCell(6);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"price[]\" SIZE=\"15\" ID=\"price"+intLine+"\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\" ></center>";
document.frmMain.hdnMaxLine.value = intLine;
//*** Column total ***//
newCell = newRow.insertCell(7);
newCell.id = newCell.uniqueID;
newCell.setAttribute("className", "css-name");
newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"total[]\" SIZE=\"15\" ID=\"total"+intLine+"\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\" ></center>";
document.frmMain.hdnMaxLine.value = intLine;
}
function RemoveRow()
{
intLine = parseInt(document.frmMain.hdnMaxLine.value);
if(parseInt(intLine) > 0)
{
theTable = document.getElementById("tbExp");
theTableBody = theTable.tBodies[0];
theTableBody.deleteRow(intLine);
intLine--;
document.frmMain.hdnMaxLine.value = intLine;
}
}
</script>
</style>
purchase.php
<table width="521" border="1" id="tbExp" cellpadding="0" cellspacing="0" style="font-size:13px; ">
<tr height="40" align="center" bgcolor="#FFFFCC">
<th width="42"><div align="center">ลำดับ </div></th>
<th width="34"><div align="center">รหัส </div></th>
<th width="76"><div align="center">รายละเอียด </div></th>
<th width="27"><div align="center">สี </div></th>
<th width="43"><div align="center">หน่วย </div></th>
<th width="40"><div align="center">จำนวน</div></th>
<th width="122"><div align="center">ราคา:หน่วย (บาท)</div></th>
<th width="119"><div align="center">รวมเป็นเงิน (บาท)</div></th>
</tr>
</table>
<table width="500" border="1" id="tbExp" cellpadding="0" cellspacing="0" style="font-size:13px; ">
<tr height="40" align="center" bgcolor="#FFFFCC">
<td width="119"><div align="center">รวมเป็นเงิน (บาท)</div></td>
<td><input type="text" id="SUMM" name="SUMM" onkeyup="allsum();"/></td>
</tr>
</table>
Tag : PHP, MySQL
Date :
2013-05-03 10:13:10
By :
lookpla26
View :
2057
Reply :
4
Code (PHP)
function allsum(rowId){
var total = document.getElementById('total'+rowId).value;
var all_total = total+total;
document.getElementById('all_total'+rowId).value = total;
}
เหมือนเดิม ไม่ยักจะหาย
ประวัติการแก้ไข 2013-05-03 10:46:28
Date :
2013-05-03 10:32:54
By :
lookpla26
เงียบเลย...
Date :
2013-05-03 10:59:27
By :
lookpla26
ยังไม่ได้เลย แก้แล้วแก้อีก ก้อเหมือนเดิม
Date :
2013-05-03 11:24:43
By :
lookpla26
Concept คือจะต้อง Loop แล้ว Sum ตามจำนวนแถวครับ ลองดูพวก parseFloat() ด้วยครับ
Date :
2013-05-03 12:14:36
By :
mr.win
Load balance : Server 03