- type:
- snippet
- category:
- Add To Cart form
- name:
- Set fields to allow only whole numbers
- versions:
- 0.6.0, 0.7.0, 0.7.1, 0.7.2
- reference:
- http://forum.foxycart.com/comments.php?DiscussionID=5120&page=1
- date:
- 2011-10-06
Set fields to only allow whole numbers
When constructing add to cart forms, it can be nice to only allow customers to enter whole numbers into a quantity field. To do this, simply paste the following script right before the closing </head>
tag of your page templates, adding a class of atc_number
to any input you want to validate to a whole number.
<script type="text/javascript"> jQuery(document).ready(function() { jQuery("input.atc_number").change(function() { var n = parseInt(jQuery(this).val()); var i = (n===+n && n===(n|0)) ? n : 0; jQuery(this).val(i); }); }); </script>