javascript - Sum subtract not work in all input fields -


how use js sum , subtract input field ,when use work 1st field 1 me out this.

 $(document).ready(function() {      //this calculates values automatically       sum();      $("#num1, #num2").on("keydown keyup", function() {          sum();      });  });    function sum() {      var num1 = document.getelementbyid('num1').value;      var num2 = document.getelementbyid('num2').value;  	var result = parseint(num1) + parseint(num2);  	var result1 = parseint(num2) - parseint(num1);      if (!isnan(result)) {            document.getelementbyid('sum').value = result;  		  document.getelementbyid('subt').value = result1;      }  }

this working...

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     <script type="text/javascript">     $(document).ready(function(){          $("#t1,#t2").keyup(function(){                 var t1=parseint($("#t1").val());                 var t2=parseint($("#t2").val());                 var t3=t1+t2;                 var t4=t1-t2;                 $("#t3").val(t3);                   $("#t4").val(t4);           });     });     </script>     <input type="text" id="t1" value="0">     <input type="text" id="t2" value="0">     <input type="text" id="t3">     <input type="text" id="t4"> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -