title: jquery: percentage of two numbers
body: <p><strong>EDITED</strong></p>
  
  <p>Thank you for everyone who offered support... the best working script I will share with you in hope that I could help others who is looking for the same solution:</p>
  
  <pre><code>    $(document).ready(function(){
  $("#price1, #price2").keyup(function() {
    var priceOne = parseFloat($("#price1").val());
    var priceTwo = parseFloat($("#price2").val());
    var rate = parseFloat($("#rate").val());
    if ($("#price1").val() &amp;&amp; $("#price2").val()){     
    $('#rate').val(((priceTwo - priceOne) / priceOne * 100).toFixed(2));
  }
  
  });
  
  $("#rate").keyup(function() {
    var priceOne = parseFloat($("#price1").val());
    var rate = parseFloat($("#rate").val());
  
     if ($("#rate").val() &amp;&amp; $("#price1").val() &amp;&amp; $("#price2").val()){
   $('#price2').val(((priceOne * rate)/ 100 + priceOne).toFixed(2));
  }
  });
  })
  </code></pre>
  
  <p>Also you can test it following this <a href="http://jsfiddle.net/dvhT5/195/" rel="nofollow">LINK</a></p>
  
  <hr>
  
  <p><strong>INITIAL QUESTION:</strong></p>
  
  <p>Please help to calculate the percentage between two numbers. I tried one way, but I did not succeed. Please tell me what is wrong, or I will appreciate if you can recommend other script which could help me</p>
  
  <p>my script:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
   &lt;script type="text/javascript"&gt;
  $("#rate").text(function() {
      var result = (parseInt(($("#price1").text(), 10) * 100)/ parseInt($("#price2").text(), 10));
      if (!isFinite(result)) result = 0;
      return result;
  });?
  &lt;/script&gt; 
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="price1"&gt;&lt;label&gt;&lt;input id="price1" type="text"&gt;&lt;/label&gt;&lt;/div&gt;
  &lt;div id="price2"&gt;&lt;label&gt;&lt;input id="price2" type="text"&gt;&lt;/label&gt;&lt;/div&gt;
  &lt;div id="rate"&gt;&lt;label&gt;&lt;input id="rate" type="text"&gt;&lt;/label&gt;&lt;/div&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>