Checking multiple input values against various other hidden minimum values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Checking multiple input values against various other hidden minimum values

DavidT75
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