Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //div:ar
  2. <div id="halvtot"></div>
  3. <div id="heltot"></div>
  4.  
  5. //tipskoll.js
  6. $(document).ready(function () {
  7.     $("#halvtot").text(getHalv());
  8.     $("#heltot").text(getHel());
  9.     $("input[id*='ctl']").click(function () {
  10.         CalculateGarderingar(this);
  11.     });
  12. });
  13.  
  14. var hel = 1;
  15. var halv = 7;
  16.  
  17. function AddHel() {    
  18.     hel = hel - 1;
  19. }
  20.  
  21. function AddHalv() {
  22.     halv = halv - 1;
  23. }
  24.  
  25. function RemoveHel() {
  26.     hel = hel + 1;
  27. }
  28. function RemoveHalv() {
  29.     halv = halv + 1;
  30. }
  31.  
  32. function getHel() {
  33.     return hel;
  34. }
  35. function getHalv() {
  36.     return halv;
  37. }
  38.  
  39. function getHelPrint() {
  40.     return ((getHel() < 0) ? 0 : getHel());
  41. }
  42.  
  43. function getHalvPrint() {
  44.     return ((getHalv() < 0) ? 0 : getHalv());
  45. }
  46.  
  47. function CalculateGarderingar(obj) {
  48.     var action = $(obj).attr('checked');
  49.     var objs = $(obj).closest("tr").find("input:checkbox");
  50.     var tot = 0;
  51.     $(objs).each(function () {
  52.         if($(this).attr('checked'))
  53.             tot++;
  54.     });
  55.     if (tot == 3) {
  56.         AddHel();
  57.         RemoveHalv();
  58.     }
  59.     if (tot == 2 && action == true) {
  60.         AddHalv();
  61.     }
  62.     if (tot == 2 && action == false) {
  63.         AddHalv();
  64.         RemoveHel();
  65.     }
  66.     if (tot == 1 && action == false) {
  67.         RemoveHalv();
  68.     }
  69.     //reload garderingar
  70.     $("#halvtot").text(getHalvPrint());
  71.     $("#heltot").text(getHelPrint());
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement