Jump to content

form event help needed :)


spires

Recommended Posts

Hi Guys.

 

I have a form which is working fine: http://www.businessmobiles.com/comcalc/test3.php

 

However, if change anything in row 1, it automatically update row 2 and 3. I think it has something to do with onkeyup event, but I not sure what.

 

If you want to see this problem, goto: http://www.businessmobiles.com/comcalc/test3.php

and change the '5' in the first field. You will then see that row 2 and 3's fields will get populated.

 

How do I stop this?

 

My code - Javascript

function calculate2(num)
{
var rCount=document.getElementById("rowCount").value;

for(i = 0; i < rCount; i++){

		if (num==1){

		document.getElementById("monthly_discount_xQ"+i).value=nan(document.getElementById("monthly_discount"+i).value)*nan(document.getElementById("STqty"+i).value);

		document.getElementById("rental_after_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("monthly_discount"+i).value);

		}else if (num==2){

		document.getElementById("monthly_discount"+i).value=nan(document.getElementById("monthly_discount_xQ"+i).value)/nan(document.getElementById("STqty"+i).value);

		document.getElementById("rental_after_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("monthly_discount"+i).value);

		}else if (num==3){

		document.getElementById("monthly_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("rental_after_discount"+i).value);

		document.getElementById("monthly_discount_xQ"+i).value=nan(document.getElementById("monthly_discount"+i).value)*nan(document.getElementById("STqty"+i).value);

		}

}

}

 

 

 

Cleaner Code, first input field:

<td height="17" class="verdana_9" align="left">
£<input name="monthly_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'"  onchange="calculate2(1);"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(1);" onblur="calculate2(1);" id="monthly_discount'.$i1.'" />
</td>

 

 

 

 

Full Code - My HTML/PHP

<?PHP
$usName = 'spires';
$client = 'tim';
$job_id = '1';

$stored_sql1 = "SELECT * FROM csv_stored WHERE stored_user='$usName' && stored_client='$client' && stored_job_id='$job_id' ORDER by stored_id ASC";
$stored_result1 = mysql_query($stored_sql1) or die ("query 2 failed".mysql_error());
$stored_count1 = mysql_num_rows($stored_result1);
for ($i1 = 0; $i1<$stored_count1; $i1++){

echo '
<form name="cashFlow'.$i1.'" action="test.php" method="post"> 			
<input name="job_id" type="hidden" value="'.$job_id.'"/>
<input name="client" type="hidden" value="'.$client.'"/>
<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor=\'#EEEEEE\';" onMouseOut="this.bgColor=\'#FFFFFF\';">';

$stored_row1 = mysql_fetch_assoc($stored_result1);
$stored_id1 = $stored_row1['stored_id'];
$stored_product1 = $stored_row1['stored_product'];
$stored_product_price1 = $stored_row1['stored_product_price'];
$stored_item1 = $stored_row1['stored_item'];
$stored_item_line_rental1 = $stored_row1['stored_item_line_rental'];
$stored_unit_price1 = $stored_row1['stored_unit_price'];
$stored_subtotal1 = $stored_row1['stored_subtotal'];
$stored_pHandset1 = $stored_row1['stored_pHandset'];
$stored_commissions1 = $stored_row1['stored_commissions'];
$stored_qty1 = $stored_row1['stored_qty'];
$stored_num1 = $stored_row1['stored_num'];

$stored_totalMR1 = $stored_row1['totalMR'];
$stored_monthly_discount1 = $stored_row1['monthly_discount'];
$stored_monthly_discount_xQ1 = $stored_row1['monthly_discount_xQ'];
$stored_duration1 = $stored_row1['duration'];
$stored_discount_total1 = $stored_row1['discount_total'];
$stored_discount_total_xQ1 = $stored_row1['discount_total_xQ'];
$stored_rental_after_discount1 = $stored_row1['rental_after_discount'];
$stored_rental_after_discount_xQ1 = $stored_row1['rental_after_discount_xQ'];

			if ($stored_product1=='add'){
			$stored_product1 = 'Add to line '.$stored_num1;
			}					

			$item_str1 = str_replace(' Month', 'mth', $stored_item1);
    $j1 = $i1+1;

$TotalMRxQ = $stored_item_line_rental1 * $stored_qty1;
$discount_total_xQ = $stored_monthly_discount_xQ1 * $stored_duration1;

$stored_rental_after_discount_xQ1 = $TotalMRxQ - $discount_total_xQ;
    echo '
<td height="17" class="verdana_9" align="left"><input name="storedID2" type="hidden" value="'.$stored_id1.'" />
<input name="rowNum" type="hidden" value="'.$i1.'" />
<input name="rowCount" type="hidden" value="'.$stored_count1.'" id="rowCount" />'.$j1.'</td>
<td height="17" class="verdana_9" align="left"><input name="STqty" type="hidden" value="'.$stored_qty1.'" id="STqty'.$i1.'" />x'.$stored_qty1.'</td>
<td height="17" class="verdana_9" align="left">'.$stored_product1.'</td>
<td height="17" class="verdana_9" align="left">'.$item_str1.'</td>
<td height="17" class="verdana_9" align="left"><input name="STlr" type="hidden" value="'.$stored_item_line_rental1.'" id="STlr'.$i1.'" />£'.$stored_item_line_rental1.'</td>
<td height="17" class="verdana_9" align="left"><input name="STmr" type="hidden" value="'.$TotalMRxQ.'" id="STmr'.$i1.'" />£'.$TotalMRxQ.'</td>
<td height="17" class="verdana_9" align="left">
£<input name="monthly_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'"  onchange="calculate2(1);"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(1);" onblur="calculate2(1);" id="monthly_discount'.$i1.'" />
</td>
<td height="17" class="verdana_9" align="left">
£<input name="monthly_discount_xQ" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount_xQ1.'"  onchange="calculate2(2);"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(2);" onblur="calculate2(2);" id="monthly_discount_xQ'.$i1.'"/>
</td>
<td height="17" class="verdana_9" align="left">
<input name="duration" type="text" size="4" class="verdana_10" height="10" value="'.$stored_duration1.'"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';" id="duration'.$i1.'" />
</td>
<td height="17" class="verdana_9" align="left">£'.$stored_discount_total1.'</td>
<td height="17" class="verdana_9" align="left">£'.$discount_total_xQ.'</td>
<td height="17" class="verdana_9" align="left">
£<input name="rental_after_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_rental_after_discount1.'"  onchange="calculate2(3);"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(3);" onblur="calculate2(3);" id="rental_after_discount'.$i1.'" />
</td>
<td height="17" class="verdana_9" align="left">
£<input name="rental_after_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="'.$stored_rental_after_discount_xQ1.'"  onchange="calculate2(4);"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(4);" onblur="calculate2(4);" id="rental_after_discount_xQ'.$i1.'" />
</td>
<td height="17" align="center">
<input type="submit" name="cashFlow'.$i1.'" size="10" value="update" /></td>';
echo '</tr>
</form>';
}
?>				

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.