1

I have a list of products where they have minimum quantities in a hidden input. Some products have multiple colours, though the same minimum quantity and I'm trying to implement a jQuery check that entries made are at least equal to the minimum.

Blank or '0' entries are fine but if it's below the minimum quantity it should set to the minimum.

HTML:

    <div class="ProductGrouping"> <!-- with colours -->
    <input id='frmQuickAdd1234c1' name='frmQuickAdd1234c1' type='text' style='width: 40px; text-align: center;' class='auto {mDec: 0}' value='' /> Black

    <input id='frmQuickAdd1234c2' name='frmQuickAdd1234c2' type='text' style='width: 40px; text-align: center;' class='auto {mDec: 0}' value='' /> White
    <input id="QuickAddMinOrderQty1234" name="QuickAddMinOrderQty1234" type="hidden" class="auto {mDec: 0}" value="6" />
    </div>
    <div class="ProductGrouping"> <!-- without colours -->
    <input id='frmQuickAdd4567' name='frmQuickAdd4567' type='text' style='width: 40px; text-align: center;' class='auto {mDec: 0}' value='' /> Product B
<input id="QuickAddMinOrderQty4567" name="QuickAddMinOrderQty4567" type="hidden" class="auto {mDec: 0}" value="3" />
</div>

jQuery:

<script type="text/javascript">
jQuery(document).ready(function(){
    if (jQuery.browser.msie) {
        jQuery("[id=^frmQuickAdd]").bind("keyup", CheckStr);
        };

    jQuery('[id=^frmQuickAdd]').change(CheckMin);
    function CheckMin(){
        var AmountStr = jQuery(this);
        var Amount = Number(AmountStr.val().replace(/[$£,]+/g,""));
        var ProductScope = jQuery(this).parent("div.ProductGrouping")
        var MinQtyStr = jQuery("[id=^QuickAddMinOrderQty]",ProductScope);
        var MinQty = Number(MinQtyStr.val().replace(/[$£,]+/g,""));
        if (parseFloat(Amount) == 0){}
        else if (parseFloat(Amount) == ''){}
        else if(parseFloat(Amount) < parseFloat(MinQty)){
            AmountStr.val(MinQtyStr.val());
            };
    };
    function CheckStr(){
        if (isNaN(jQuery(this).val() )) {
            var ProductScope = jQuery(this).parent("div.ProductGrouping")
                jQuery(this).val(jQuery("[id=^QuickAddMinOrderQty]",ProductScope).val())
        }
    };
});
</script>

Is there something obviously wrong with this? It isn't performing the minimum check and I'm really not sure why.

Thanks

David

2
  • I really don't understand this whole question.
    – Gausie
    Jul 20, 2011 at 9:16
  • I have various input boxes, grouped within a '.ProductGrouping'. Each '.ProductGrouping' has a hidden input which holds a Minimum Qty value. This Minimum Qty needs to be applied to the other input boxes within the '.ProductGrouping' when they are entered.
    – DavidT
    Jul 21, 2011 at 15:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.