carolineschnapp
5/4/2011 - 9:11 PM

Limit to 1 — add at the bottom of cart.liquid

Limit to 1 — add at the bottom of cart.liquid

<script>
if (typeof jQuery === 'undefined') {
  document.write('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"><\/script>');
  document.write('<script type="text/javascript">jQuery.noConflict();<\/script>');
}
</script>

<script type="text/javascript">
jQuery(function() {
  var needs_update = false;
  jQuery(':text[name^=updates]').each(function() {
    if (jQuery(this).val() !== '1') {
      needs_update = true;
      jQuery(this).val(1);
    }
  });
  if (needs_update) {
    jQuery('form[action="/cart"]').get(0).submit();
  }
  jQuery(':text[name^=updates]').change(function() {    
    if (parseInt(jQuery(this).val(), 10) > 1) {
      jQuery(this).val(1);
      jQuery('form[action="/cart"]').get(0).submit();
    }
  });
});
</script>