I have an order page where the customer needs to only be able to order from 1 up to the number in stock.
$(document).ready(function()
{
$("#AddToCartForm").validate({
rules: {
quantity: { required: true, range: [1, $('.size_max').val()] }
}
});
});
Even though there is a hidden field with the id “size_max” and a value of 5, this returns
Please enter a value between 1 and NaN
when any number is put in the quantity field.
How can I set the upper bound of the range dynamically?
You’ve mentioned that you have a hidden field with an id, but you are using a class selector in your code. Try changing
$('.size_max')to$('#size_max')in your code.