Jump to content

form help needed


spires

Recommended Posts

Hi Guys

 

I'm trying to build a form the does on the fly calculations.

Please see: http://www.businessmobiles.com/comcalc/test.php

 

The form need to fill out the blank fields when a user types in any of the fields, using onKeyUp event.

So far I can only get the last field to work.

 

So far no one else can seem to help. So any advice or help on how to do this would be great.

 

I know it's the Javascript, but not to sure what.

 

My code

<?PHP
include("../dbconnect.php");
include("../Library/head.php");
include("include.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Comcalc</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript">


function fixCashFlow(i, t, q) {
	if (t=="mdisq") {
		// We need to set
		v=i.monthly_discount.value;
		i.monthly_discount_xQ.value=Math.floor((v*q*100))/100;
	} else {
		v=i.monthly_discount_xQ.value;
		i.monthly_discount.value=Math.floor(((v/q)*100))/100;
	}
}

function fixDiscount(frm, mlr, q, s) {
	mlr=parseFloat(mlr);

	if (s==false) {
		frm.monthly_discount.value=mlr-frm.rental_after_discount.value;
		fixCashFlow(frm, 'mdisq', q);
	} else {
		frm.rental_after_discount.value=Math.floor((frm.rental_after_discount_xQ.value/q)*100)/100;
		fixDiscount(frm, mlr, q, false);
	}

}

</script>
</head>

<body>
<table width="930" border="0" cellspacing="0" cellpadding="0">
<tr>
  <td height="20" colspan="14" align="left" valign="middle" bgcolor="#000000"><span class="title"><strong>Cash flow:</strong></span></td>
</tr>
<tr>
 <td width="32" height="20" align="left" valign="middle"><span class="verdana_10">Line</span></td>
  <td width="29" height="20" align="left" valign="middle"><span class="verdana_10">Qty</span></td>
  <td width="157" height="20" align="left" valign="middle"><span class="verdana_10">Products / Handsets</span></td>
  <td width="157" height="20" align="left" valign="middle"><span class="verdana_10">Tariff Name</span></td>
  <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly line rental</span></td>
  <td width="40" height="20" align="left" valign="middle"><span class="verdana_10">Total MR <br />
   x Q</span></td>
  <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly discount</span></td>
  <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly discount <br />
   X Q</span></td>
	<td width="58" height="20" align="left" valign="middle"><span class="verdana_10">Duration (months)</span></td>
	<td width="70" height="20" align="left" valign="middle"><span class="verdana_10">Discounted Total</span></td>
	<td width="66" height="20" align="left" valign="middle"><span class="verdana_10">Discounted<br />
	 Total X Q</span></td>
	<td width="57" height="20" align="left" valign="middle"><span class="verdana_10">Rental after discounts</span></td>
	<td width="61" height="20" align="left" valign="middle"><span class="verdana_10">Rental after discounts <br />
	 X Q</span></td>
  <td width="40" height="20" align="left" valign="middle"> </td>
</tr>
<?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;


    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">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="'.$stored_totalMR1.'" id="STmr'.$i1.'" />£'.$stored_totalMR1.'</td>
<td height="17" class="verdana_9" align="left">

£<input name="monthly_discount" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixCashFlow(document.cashFlow'.$i1.', "mdisq", '.$stored_qty1.');" />

</td>
<td height="17" class="verdana_9" align="left">

£<input name="monthly_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount_xQ1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixCashFlow(document.cashFlow'.$i1.', "mdis", '.$stored_qty1.');" />

</td>
<td height="17" class="verdana_9" align="left">
<input name="duration" type="text" size="5" class="verdana_10" height="10" value="'.$stored_duration1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';" />
</td>
<td height="17" class="verdana_9" align="left">£'.$stored_discount_total1.'</td>
<td height="17" class="verdana_9" align="left">£'.$stored_discount_total_xQ1.'</td>
<td height="17" class="verdana_9" align="left">

£<input name="rental_after_discount" type="text" size="5" class="verdana_10" height="10" value="'.$stored_rental_after_discount1.'"  onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixDiscount(document.cashFlow'.$i1.', '.$stored_item_line_rental1.', '.$stored_qty1.', false);" />

</td>
<td height="17" class="verdana_9" align="left">

£<input name="rental_after_discount_xQ" type="text" size="7" class="verdana_10" height="10" value="'.$stored_rental_after_discount_xQ1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixDiscount(document.cashFlow'.$i1.', '.$stored_item_line_rental1.', '.$stored_qty1.', true);" />

</td>
<td height="17" align="center">
<input type="submit" name="cashFlow'.$i1.'" size="10" value="update" /></td>';
echo '</tr>
</form>';

}
?>				

</table>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/162942-form-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.