Expand|Select|Wrap|Line Numbers
- <table border="2" cellspacing="2" cellpadding="2" width=100% id="myTable1">
- <tr>
- <th> </th>
- <th>Part no.</th>
- <th>Description</th>
- <th>Price (£)</th>
- <th>Quantity</th>
- <th>Discount</th>
- <th>Supplier</th>
- <th>Sub Total</th>
- </tr>
- </table>
- <span>£<span id ="total"></span></span>
Expand|Select|Wrap|Line Numbers
- var tbl = document.getElementById('myTable1');
- var lastRow = tbl.rows.length;
- // alert (lastRow);
- // if there's no header row in the table, then iteration = lastRow + 1
- var iteration = lastRow;
- var row = tbl.insertRow(lastRow);
- // cell number
- var cellLeft = row.insertCell(0);
- var textNode = document.createTextNode(iteration);
- cellLeft.appendChild(textNode);
- // part number
- var cellpno = row.insertCell(1);
- var t_pno = document.createTextNode(part_no);
- cellpno.appendChild(t_pno);
- //description
- var celldesc = row.insertCell(2);
- var t_desc = document.createTextNode(description);
- celldesc.appendChild(t_desc);
- //price
- var cellprice = row.insertCell(3);
- var t_price = document.createTextNode(price);
- cellprice.appendChild(t_price);
- //quantity
- var cellqty = row.insertCell(4);
- var t_qty = document.createTextNode(quantity);
- cellqty.appendChild(t_qty);
- //discount
- var celldisc = row.insertCell(5);
- var t_disc = document.createTextNode(discount);
- celldisc.appendChild(t_disc);
- //supplier
- var cellsup = row.insertCell(6);
- var t_sup = document.createTextNode(supplier);
- cellsup.appendChild(t_sup);
- //subtotal
- var cellsub = row.insertCell(7);
- var sub = quantity * price;
- var sub1 = (sub / 100) * discount;
- var sub2 = sub - sub1;
- var result = sub2.toFixed(2);
- var t_sub = document.createTextNode(result);
- cellsub.appendChild(t_sub);
- document.getElementById('part_no').value = "";
- document.getElementById('quantity').value = "";
- document.getElementById('description').value = "";
- document.getElementById('price').value = "";
- document.getElementById('discount').value = "";
- total();