title: How to calculate amount to be paid from input box values using Javascript?
body: <p>I have a problem in automatically calculating the amount to be paid in a html table.</p>
  
  <p>The html code looks like this:</p>
  
  <pre><code>&lt;td&gt;
      &lt;input type="hidden" id="getAvailability" readonly class="form-control input-sm" /&gt;
      &lt;strong&gt;Qty&lt;/strong&gt;&lt;br /&gt;
      &lt;input type="text" tabindex="1" name="Qty" id="getQty" class="form-control input-sm NumbersOnly" /&gt;
  &lt;/td&gt;
  &lt;td&gt;
      &lt;strong&gt;Rate&lt;/strong&gt;&lt;br /&gt;
      &lt;input type="text" name="Rate" id="getRate" readonly class="form-control input-sm " /&gt;
  &lt;/td&gt;
  &lt;td&gt;
      &lt;strong&gt;Amount&lt;/strong&gt;&lt;br /&gt;
      &lt;input type="text" name="Amount" id="getAmount" readonly class="form-control input-sm " /&gt;
  &lt;/td&gt; 
  </code></pre>
  
  <p>Bellow this table i have another table with SQL entries, from where i select a row. On clicking a row from this table the following function is called:</p>
  
  <pre><code>$(function () {
          $('#getStockID').val($.trim(cells[0].innerHTML));
          $('#getItem').val($.trim(cells[1].innerHTML));
          $('#getAvailability').val($.trim(cells[3].innerHTML));                       
          $('#getRate').val($.trim(cells[4].innerHTML));
      });
  </code></pre>
  
  <p>When i enter the quantity in first table i would like to have to amount to be paid calculated:</p>
  
  <pre><code>$('#getQty').keyup(function () {
      var available = Number($('#getAvailability').val());
      var quantity = Number($('#getQty').val());
      var rate = Number($('#getRate').val());
      if (quantity &gt; available) {
          $('#getQty').val(available);
          quantity = available;
      }
      var amount = (quantity * rate);               
      $("#getAmount").val(amount.toFixed(2));
  });
  </code></pre>
  
  <p>Using this code, i get NaN in the cell.
  Please advice, i spent way too many hours on this issue, and i'm out of ideas.
  Thank you very much!</p>