subtraction using javascript
<p>The below coding is my doubt. the total fees value is fetched from db. and paid is currently we enter. now i want that if i enter any value in paid, the entered value is subtract from db value and new value is display in bal fees text box and as well as store in db.</p>

<p>my coding is...</p>

<pre><code>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;script language="javascript"&gt;
function doMath() 
{
    var oldbal= parseInt(document.getElementById('totalfees').value);
    var paid= parseInt(document.getElementById('paid').value);
    var totalfees = oldbal-paid;
    document.getElementById('totalfees').value = totalfees;
}
&lt;/script&gt;

&lt;/HEAD&gt;
&lt;body&gt;

&lt;?php
//fteching query
include("db.php");
$billtype_id = $_GET['billtype_id'];
$result=mysql_query("select * from bill_type where billtype_id=$billtype_id");
while($res=mysql_fetch_array($result))
{
$totalfees=$res['totalfees'];
}
//inserting query
$sql=mysql_query("insert into fees_admin values totalfees='$balfees' WHERE billtype_id='$billtype_id'",$conn);


include("config.php");
$balfees=$_POST['totalfees'];
$sql=mysql_query("insert into fees_admin values totalfees='$balfees' WHERE billtype_id='$billtype_id'",$conn);
?&gt;
//html form

&lt;form name="form" method="post" action="&lt;?php $_SERVER['PHP_SELF'];?&gt;"&gt;
&lt;table&gt;
&lt;tr&gt;
  &lt;td&gt;Total Fees :&lt;/td&gt; 
  &lt;td&gt;&lt;input name="total" type="text" id="oldbal" value="&lt;?php echo $totalfees;?&gt;" readonly="true" style="background-color:#FFFFFF"&gt;&lt;/td&gt;
&lt;/tr&gt; 
&lt;tr&gt;

  &lt;td&gt;Paid :&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" id="paid" name="paid" onKeyUp="doMath();"&gt;&lt;/td&gt;
&lt;/tr&gt; 
&lt;tr&gt;

  &lt;td&gt;Bal Fees&lt;/td&gt;
  &lt;td&gt;&lt;input name="totalfees" type="text"  id="totalfees" readonly="true" style="background-color:#FFFFFF"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
</code></pre>

<p>Thanks for reading. please clear my doubt..</p>
