I am making what I call a PM (Preventive Maintenance) Kit list. My users will use this list to generate a printable sheet to tell me what they used out of there kit. The list includes pricing per part and I would like the list to calculate the costing as they enter each item. So a total per line and an overall total cost.
I have included a snap shot of the page and below is the code.
I can do this sort of thing on a small scale with just adding two lines but I am not sure how to modify it to handle this scale. You can see the script towards the bottom of the page. That is my lame attempt to make the per line costing happen but NOTHING happens.
<?php
require "../config/bpts_config.php";
// Start the session
//session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>PM Kit Listing - Edit</title>
<?php include("../includes/pm_kit_css_js_includes.php"); ?>
</head>
<body>
<div id="container">
<div id="header_container">
<?php include("../includes/header.php"); ?>
</div>
<div id="upper_container">
<div id="upper_2col_left"></div>
<div id="upper_2col_right"> <a href='index.php'>Back To Listing</a> </div>
</div>
<div id="body_container">
<div id="body_content">
<?php
$pm_kit_type_ID = (int) $_GET['pm_kit_type_ID'];
// Select all the pm kit items, ordered by Part Name:
$pm_kit_parts_SQL = mysql_query("SELECT * from pm_kit_parts JOIN sage_part_listing
WHERE pm_kit_type_ID = $pm_kit_type_ID
AND pm_kit_parts.SKICPart = sage_part_listing.SKICPart
AND 'status' = 0
ORDER BY `sage_part_listing`.`ID` ASC") or die(mysql_error());
?>
<table>
<tr>
<th>Qty</th>
<th>Part Number</th>
<th>Description</th>
<th>Cost Each</th>
<th width="60px">Qty Used</th>
<th width="60px">Total</th>
<th width="60px">Spares</th>
<th width="60px">Total</th>
</tr>
<?php
while($info = mysql_fetch_array($pm_kit_parts_SQL)) {
?>
<tr>
<? $parts_ID = $info['pm_kit_parts_ID']; ?>
<td align="center"><? echo $info['quantity']; ?></td>
<td><? echo $info['ID']; ?></td>
<td><? echo $info['Description1'] . $info['extended_description']; ?></td>
<td align="right"><? echo "$" . number_format($info['PartCost'],2, '.', ','); ?></td>
<td><input style="text-align:center" name="qty_used" type="text" size="8" onclick="calculateTotal<? echo $parts_ID; ?>(this.form)"></td>
<td><input style="text-align:right" name="qty_used_total" type="text" size="8"></td>
<td><input style="text-align:center" name="spares_left" type="text" size="8"></td>
<td><input style="text-align:right" name="spares_left_total" type="text" size="8"></td>
</tr>
<script language="javascript" type="text/javascript">
function calculateTotal<? echo $parts_ID; ?>(myForm) {
var item1 = Number(myForm.qty_used.value);
var qty_total;
if (myForm.item1.value==true) { qty_total = item1 * <? $info['PartCost']; ?>; }
else if myForm.item1.value==false) { order_total = 0.00; }
myForm.qty_used_total.value = order_total.toFixed(2);
}
</script>
<?php } ?>
</table>
</div>
</div>
</body>
</html>
Ken