Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to subtract input values
    primarykey
    data
    text
    <p>i have a php page where i would be able to subtract two values from which one is fetched from mysql database and another one is entered by user itself. What i want exactly is while entering the value in second input field the entered value should be subtracted from first input value calling from database and the subtracted value should be visible in another input... Code is...</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;style&gt; td {font-size:13px;} &lt;/style&gt; &lt;script src="jquery-1.8.3.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function(){ $('input').each(function() { $(this).keyup(function(){ calculatedis($(this)); }); }); }); function calculatedis(src) { var sub = 0; var sumtable = src.closest('.sumtable'); sumtable.find('input').each(function() { var amt1 = $('input[name="amt1"]').val(); var amt2 = $('input[name="amt2"]').val(); sub = (amt1 - amt2) }); sumtable.find(".netAmt").val(sub.toFixed(2)); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form class="inward"&gt; &lt;?php include("dbconnection.php"); $sql = "SELECT id,price FROM table1 WHERE id='3' ORDER BY id"; $res = mysql_query($sql) or die(mysql_error()); echo "&lt;table border='1' align='center' cellspacing='0' cellpadding='3' class='sumtable'&gt;"; echo "&lt;tr bgcolor='#CCCCCC' height='30'&gt;"; echo "&lt;td&gt;Price&lt;/td&gt;"; echo "&lt;td&gt;Discounted Amt&lt;/td&gt;"; echo "&lt;td&gt;Net Amt&lt;/td&gt;"; echo "&lt;/tr&gt;"; while($row2=mysql_fetch_array($sql2)) { //change row color alternately $i++; $color = ($i%2) ? "#f8f8ff" : "#f0fff0"; echo "&lt;tr bgcolor=" . $color . " onmouseover='ChangeBackgroundColor(this)' onmouseout='RestoreBackgroundColor(this)'&gt; $price = $row2["price"]; if (strlen(trim($price)) == 0) { echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;"; } else { echo "&lt;td valign='top'&gt;&lt;input name='amt1' value=" . $price . " size='5'/&gt;&lt;/td&gt;"; } echo "&lt;td valign='top' &gt;&lt;input name='amt2' size='5'/&gt;&lt;/td&gt;"; echo "&lt;td valign='top'&gt;&lt;input name='netamt' class='netAmt' size='5'/&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; echo "&lt;br&gt;"; echo "&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;center&gt;"; echo "&lt;input type='submit' name='submit' value='Save' style='cursor:pointer;cursor:hand;'&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"; echo "&lt;input type='reset' name='clear' value='Clear' style='cursor:pointer;cursor:hand;'&gt;"; echo "&lt;/center&gt;"; ?&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Don't Know what's wrong with this any kind of help would be appreciated............</p> <p>In addition to this.....can i get the sum of these subtracted values at the end of loop like Total is: </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload