I need this to happen for multiple lines that a created from a while loop.
This script adds the 2 input text boxes together and shows the sum in the third, this also simulates what I need but is not dynamic in case I need to generate more lines.
Working*
Code: Select all
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
document.autoSumForm.thirdBox.value = (one * 1) + (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
</script>
<div style="width: 200px; text-align: center;">
<form name="autoSumForm">
<input class="right" type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>
+ <input class="right" type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>
= <input class="right" type="text" value="0" name="thirdBox">
</form>
</div>
Code: Select all
<table id="ind_pro">
<?
/* Generates a row in the table with a Line Number
---------------------------------*/
while ($pro16_fa = mysql_fetch_assoc($pro16)){
/* Define the Line ID
-----------------------------*/
$lin_id = $pro16_fa['lin_id'];
/* Find all products that are on this line
-----------------------------*/
$pro1 = mysql_query("SELECT * FROM pro_inf WHERE lin_id='$lin_id' AND pro_status!='0' AND act_id='$act_id' ORDER BY pro_model ASC") or die(mysql_error());
?>
<tr>
<td class="w10">Line <? echo $lin_id; ?></td>
<td class="w90">
<ul>
<?
/* List products from SQL database that are associated with the line id in a list
---------------------------------*/
while ($pro1_fa = mysql_fetch_assoc($pro1)){
?>
<li style="font-size: 11px;">
<input type="hidden" name="ind[<? echo $pro1_fa['pro_id']; ?>]" class="check" value="<? echo $pro1_fa['pro_id']; ?>" />
<!-- onFocus change this input text to 1, I need this to be total'd automatically at the end of the line. -->
<input type="text" size="2" name="qty[<? echo $pro1_fa['pro_id']; ?>]" class="check" onfocus="clearText(this)" value="0" />
<? echo $pro1_fa['pro_descrip']; ?>
</li>
<? } ?>
<li>
<!-- This is where the total for this line needs to be displayed. -->
<input type="text" name=totalForLine[<? echo $lin_id; ?]" />
</ul>
</td>
</tr>
<? } ?>
</table>