Advertisement
Guest User

Untitled

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