Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(function($) {
  2.     $(document).ready(function() {
  3.         $('form.cart').submit(function(e) {
  4.             if ($(this).find('.qty').val() < 1) {
  5.                 e.preventDefault();
  6.                 alert('Select Product Quantity first');
  7.             }
  8.         });
  9.     });
  10.     jQuery(function($) {
  11.         $(document).ready(function() {
  12.             $('form.cart').submit(function(e) {
  13.                 if ($(this).find('.qty').val() < 1) {
  14.                     e.preventDefault();
  15.                     alert('Select Product Quantity first');
  16.                 }
  17.             });
  18.         });
  19.  
  20.         $(document).on('click', '.plus, .minus', function() {
  21.  
  22.             // Get values
  23.             var $qty =0,
  24.                 currentVal = 0,
  25.                 max = parseFloat($qty.attr('max')),
  26.                 min = parseFloat($qty.attr('min')),
  27.                 step = $qty.attr('step');
  28.  
  29.             // Format values
  30.             if (!currentVal || currentVal === '' || currentVal === 'NaN') currentVal = 0;
  31.             if (max === '' || max === 'NaN') max = '';
  32.             if (min === '' || min === 'NaN') min = 0;
  33.             if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') step = 1;
  34.  
  35.             // Change the value
  36.             if ($(this).is('.plus')) {
  37.  
  38.                 if (max && (max == currentVal || currentVal > max)) {
  39.                     $qty.val(max);
  40.                 } else {
  41.                     console.log(currentVal)
  42.                     $qty.val(currentVal + parseFloat(step));
  43.                 }
  44.  
  45.             } else {
  46.  
  47.                 if (min && (min == currentVal || currentVal < min)) {
  48.                     $qty.val(min);
  49.                 } else if (currentVal > 0) {
  50.                     $qty.val(currentVal - parseFloat(step));
  51.                 }
  52.  
  53.             }
  54.  
  55.             // Trigger change event
  56.             $qty.trigger('change');
  57.         });
  58.     });
  59.  
  60.  
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement