4

Hi i want to calculate two input field values and result will show in third input field so i want to write code in ajax page

<input id="a1" type="text" />
<input id="a2" type="text" onblur="Calculate();"  />
<input id="a3" type="text" name="total_amt" value="" />

here javascript function

 <script>


function Calculate()
{
var resources = document.getElementById('a1').value;
var minutes = document.getElementById('a2').value; 
document.getElementById('a3').value=parseInt(resources) *       parseInt(minutes);
 document.form1.submit();
   }
 </script>

starting its working but nw its not working please help me

Thanks in Advance

Muhammet Demir
  • 1,995
  • 5
  • 21
  • 42

4 Answers4

7

Look this! Work it. http://jsfiddle.net/op1u4ht7/2/

<input id="a1" type="text" />
<input id="a2" type="text" onblur="calculate()"  />
<input id="a3" type="text" name="total_amt" />

calculate = function()
{
    var resources = document.getElementById('a1').value;
    var minutes = document.getElementById('a2').value; 
    document.getElementById('a3').value = parseInt(resources)*parseInt(minutes);

   }
Maybe Gordon
  • 130
  • 5
3

Try AutoCalculator https://github.com/JavscriptLab/autocalculate Calculate Inputs value and Output By using selector expressions

Just add an attribute for your output input like data-ac="(#firstinput+#secondinput)"

No Need of any initialization just add data-ac attribute only. It will find out dynamically added elements automatically

FOr add 'Rs' with Output just add inside curly bracket data-ac="{Rs}(#firstinput+#secondinput)"

Justine Jose
  • 130
  • 2
  • 7
0

My code is from an answer above. Special thank for you!

calculate = function (a, p, t) {
        var amount = document.getElementById(a).value;
        var price = document.getElementById(p).value;
        document.getElementById(t).value = parseInt(amount)*parseInt(price);}
<input type="number" id="a0" onblur="calculate('a0', 'p0', 't0')">
<input type="number" id="p0" onblur="calculate('a0', 'p0', 't0')">
<input type="number" id="t0" >
<hr>
<input type="number" id="a1" onblur="calculate('a1', 'p1', 't1')">
<input type="number" id="p1" onblur="calculate('a1', 'p1', 't1')">
<input type="number" id="t1" >
Gim
  • 79
  • 1
  • 4
0

put in you form id="form1"

the JavaScript is look like this.

calculate = function()
{
  var resources = document.getElementById('a1').value;
  var minutes = document.getElementById('a2').value; 
  document.getElementById('a3').value = parseInt(resources)*parseInt(minutes);
  document.form1.submit();
}
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34