Login   Register  
PHP Classes
elePHPant
Icontem

Calculate amount automatically

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Classes blog  >  PHP standards discuss...  >  All threads  >  Calculate amount automatically  >  (Un) Subscribe thread alerts  
Subject:Calculate amount automatically
Summary:Invoice System cannot compute amount automatically
Messages:1
Author:Nonso Azuka
Date:2011-07-20 18:22:32
Update:2011-07-20 19:12:03
 

  1. Calculate amount automatically   Reply  
Picture of Nonso Azuka
Nonso Azuka
2011-07-20 19:12:03
I designed an invoice system that add rows automatically and computes the results, print it in another file that can be downloaded by other users.can i get help on how to multiply the price and quantity to get amount?

this is my code:


<SCRIPT LANGUAGE="JavaScript">
function showamt() {

//var unitprice = document.form1.unitprice[].value;
//var qty = document.form1.qty[].value;
//amount = unitprice*qty;
//document.form1.amount[].value = amount;

var a= document.getElementById('unitprice[this]');
var b= document.getElementById('qty[this]');
var c = Math.ceil(a.value*b.value);
alert(b);
document.getElementById('amount[this]').value =c;
}

</script>
<SCRIPT language="javascript">
function addRow(tableID) {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var colCount = table.rows[0].cells.length;

for(var i=0; i<colCount; i++) {

var newcell = row.insertCell(i);

newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}

switch(newcell.childNodes[0].name) {
case "s_no[]":
newcell.childNodes[0].value = rowCount + 1;
break;
}
}
}

function deleteRow(tableID) {
var tbl = document.getElementById(tableID);
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);

}

</SCRIPT>