Auto calculation of input fields

Auto calculation of input fields

Hi all,
I am trying to make this code bellow to work, I would really appreciate your help. Basicly it is Calculation of sum of three input fields and then multiplication with two other fields. The final result should be shown in a input field pcamount.

Here is the exemple in jsFiddle: http://jsfiddle.net/D98PW/

Bellow is the jquery script and the html

Thanks in advance for your help!

  1. $(document).ready(function() { $('input[name=deposit], input[name=minpremium], input[name=adjpremium],input[name=procombaserate], input[name=profcomper], input[name=pcamount]').change(function(e) { var total_mnozi = 0; var total=0; var $row = $(this).parent(); var dep = $row.find('input[name=deposit]').val(); var minpre = $row.find('input[name=minpremium]').val(); var adjpre = $row.find('input[name=adjpremium]').val(); var procombase = $row.find('input[name=procombaserate]').val(); var profcomper = $row.find('input[name=profcomper]').val(); // var pcamount= $row.find('input[name=pcamount]').val(); // total_mnozi= procombase * profcomper; $('dep, minpre, adjpre').each(function() { total += parseFloat($(this)); total_mnozi = total * procombase * profcomper; $row.find('input[name=pcamount]').val( total_mnozi); }); }); });

  1. <table >
  2.  <tr>
  3. <td><label>MIN Premium</label></td>
  4.  <td class="toadd"><input type="text" class="input1" name="minpremium" id="minpremium" value="">
  5. </td> </tr>
  6.  <tr><td><label>Deposit</label></td>
  7. <td ><input type="text" name="deposit" id="deposit" class="input1" size="20" value=""></td>
  8. </tr>
  9.  <tr><td><label>Adjustment Premium</label></td>                           
  10. <td ><input type="text" name="adjpremium" id="adjpremium" class="input1" size="20" value=""></td
  11. <td><label>Return Premium</label></td>
  12. <td><input type="text" class="input1" name="returnpremium" id="returnpremium"></td>
  13. </tr> <tr>   
  14.  <td><label>Tax Allocation</label></td>
  15. <td><input type="text" class="input1" name="taxalloc" id="taxalloc"></td>
    <td><label>Premium Base Rate</label></td>
  16.  <td><input type="text" class="input1" name="pramiumbase" id="pramiumbase"></td>
  17. </tr><tr>
  18.  <td><label>Adjustable Rate</label></td
  19. <td><input type="text" class="input1" name="adjrate" id="adjrate" class="input1" size="20" value=""></td
  20. <td><label>PC Base Rate</label></td>  
  21. <td><input type="text" class="input1" name="procombaserate" id="procombaserate" class="input1" size="20" value=""></td> </tr>
  22.  <tr> <td><label>Profit Commission %</label></td>

  23. <td><input type="text" class="input1" name="profcomper" id="profcomper" value=""></td>
  24. <td><label>PC Amount</label></td>  
  25. <td><input type="text" class="input1" name="pcamount" id="pcamount" class="input1" size="20" >
  26.   </td>
  27.  </table