Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Created May 4, 2011 21:11
Show Gist options
  • Save carolineschnapp/956046 to your computer and use it in GitHub Desktop.
Save carolineschnapp/956046 to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment