jquery - Calculation in javascript -


my html looks that:

<input type="text" id="qty"> <input type="text" id="unp"> <input type="text" id="tv">  <input type="text" id="qty2"> <input type="text" id="unp2"> <input type="text" id="tv2">  <input type="text" id="qty3"> <input type="text" id="unp3"> <input type="text" id="tv3">  ... 

how can calculate tv = qty*unp , tv2 = qty2*unp2?

function tvfunction() {          var inputtags = document.getelementsbytagname('input');      for(var i=1; i<=inputtags.length ; i++){              if(i == 1)           {          var qty= document.getelementbyid('qty').value;          var unp = document.getelementbyid('unp').value;          var result= number(qty)*number(unp);          document.getelementbyid('tv').value = result;          }       else        {          var qty= document.getelementbyid('qty'+i).value;          var unp = document.getelementbyid('unp'+i).value;          var result= number(qty)* number(unp);          document.getelementbyid('tv'+i).value = result;       }    }    }
     <input type="text" id="qty">  <input type="text" id="unp">  <input type="text" id="tv">      <input type="text" id="qty2">  <input type="text" id="unp2">  <input type="text" id="tv2">      <input type="text" id="qty3">  <input type="text" id="unp3">  <input type="text" id="tv3">    <input type="text" id="qty4">  <input type="text" id="unp4">  <input type="text" id="tv4">    <input type="text" id="qty5">  <input type="text" id="unp5">  <input type="text" id="tv5">    <input type="text" id="qty6">  <input type="text" id="unp6">  <input type="text" id="tv6">    <input type="text" id="qty7">  <input type="text" id="unp7">  <input type="text" id="tv7">    <input type="text" id="qty8">  <input type="text" id="unp8">  <input type="text" id="tv8">        <input type="button" id="btn3"             onclick="tvfunction()" value="calculate">


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -