PHP Classes

Calculate amount automatically

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in

      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
Author:Nonso Azuka
Date:2011-07-20 18:22:32
Update:2011-07-20 19:12:03

  1. Calculate amount automatically   Reply   Report abuse  
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:

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);
document.getElementById('amount[this]').value =c;

<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;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
case "checkbox":
newcell.childNodes[0].checked = false;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;

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

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