I am creating a form which dynamically creates a list of options to purchase. The list is generated from a database. The PHP is
<?php
for($i = 1; $i <= $opt_count; $i++){
$desc = $options['description'][$i];
$prc = $options['price'][$i];
$type = $options['type'][$i];
$size[$i] = ' ';
$option_text = <<<TABLE
<tr>
<td>$desc</td>
<td style="text-align:center">$size[$i]</td>
<td style="text-align:center"><input type="text" name="qty[$i]" onchange="calculate()" size="2" /></td>
<td style="text-align:right">$prc[$i]</td>
<td class="right_align"><input type="text" style="text-align:right" name="total[$i]" size="2" readonly="readonly" /></td>
</tr>
TABLE;
echo $option_text;
} // for loop
?>
My problem is that I don't know how to create the JavaScript calculate() function to calculate the total for a line item, and also a grand total (an input field that is not shown in this snippet).