To include a quantity drop down on your product page, refer to the instructions provided on a specific page in the Shopify documentation.
<label for="quantity">Qty: </label>
<select id="quantity" name="quantity">
{% for i in (1..10) %}
<option value="{{ i }}">{{ i }}</option>
{% endfor %}
</select>
(Ensure you use name="quantity"
to pass the value to the cart.)
The issue with limiting the maximum quantity based on remaining stock is that the quantity is linked to variants, not products. It might work for a single variant by adjusting the loop as follows:
{% for i in (1..product.variants.first.inventory_quantity) %}
If dealing with multiple variants, consider restricting the quantity in the cart instead. Here's an example for cart.liquid:
<select id="updates_{{ item.id }}" name="updates[]">
{% for i in (1..item.variant.inventory_quantity) %}
<option value="{{ i }}"{% if item.quantity == i %} selected{% endif %}>{{ i }}</option>
{% endfor %}
</select>