Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <form action="" method="POST">
  2. <input type="text" name="text1" id="text1" class="sum" /><br />
  3. <input type="text" name="text2" id="text2" class="sum" /> <br />
  4. <input type="text" name="text3" id="text3" class="sum" /> <br />
  5.  
  6. <input type="checkbox" id="chk1" value="4" class="sum" /><label for="chk1">4</label> <br />
  7. <input type="checkbox" id="chk2" value="10" class="sum" /><label for="chk2">10</label> <br />
  8. <select name="u1" class="chkOptions">
  9. <option value="0" selected="selected">нет</option>
  10. <option value="120">1 упаковка</option>
  11. <option value="240">2 упаковки</option>
  12. <option value="300">3 упаковки</option>
  13. </select>
  14. <input type="text" name="text" id="text">
  15. </form>
  16. <script>
  17. $(function() {
  18. var calc = function() {
  19. var sum = 0;
  20. fields.each(function() {
  21. var el = $(this),
  22. type = el.attr("type");
  23.  
  24. if ((type == "text") || (type == "checkbox" && el.attr("checked"))) {
  25. sum += parseInt($(this).val(), 10) || 0;
  26. }
  27. $('#text').val(sum);
  28.  
  29. });//end each
  30. },//end calc
  31.  
  32. fields = $(".sum");
  33.  
  34. fields.change(calc);
  35.  
  36. });
  37. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement