Tuesday, 6 August 2013

jQuery "val" Check Value of QTY input field and display error if is greater than stock available

jQuery "val" Check Value of QTY input field and display error if is
greater than stock available

I have a small jQuery problem, I can echo with PHP how many of a certain
product is in stock. I would like to use jQuery to check the input and if
the value is higher than the amount in stock then there to be a red
warning popup.
<script>
jQuery("input").keyup(function () {
var value = jQuery(this).val();
if( value > <?php echo $stock_qty ?> )
jQuery( '#stock-info-block' ).show();
}).keyup();
</script>
<div class="stock-info-block" style="display: none;">
<p><?php echo $this->__('Sorry we only have %d left in Stock',
$stock_qty); ?></p>
</div>
I have this but it doesn't seem to be working, can anyone help?

No comments:

Post a Comment