For my shopping cart I’m using a bit of javascript to update my select menu for a product amount to add to cart. It works great on updating on the fly depending on the stock left of a particular combination of ‘S’ in ‘Red’. Though I’m trying to limit this select list of only 5, even if more then 5 is reported. Here is what I have thus far to rewrite the drop-down list:
<input type="hidden" id="store_product_stock" class="store_product_stock" />
<select name="item_qty" id="item_qty">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<script>
$(function() {
$('#store_product_stock').change(function() {
// get the new stock level
var stock = $(this).val();
// remove existing dropdown options
$('#item_qty').empty();
// add dropdown options again
for (var i=1; i <= stock; i++) {
$('#item_qty').append('<option value="'+i+'">'+i+'</option>');
}
});
});
</script>
can you not just force 5 when stock is over 5 like: