Reputation: 5
HTML CODE
<div><input type="text" disabled value="<?php echo $res['pro_quantity']; ?>" id="available"></div>
JS CODE
function quantity_check()
{
var avail = $('#available').val();
var quant = $('#quantity').val();
//alert(avail)
if (quant<=avail){
return true;
}
else
$('#quantity').val(0);
}
here is what when i enter any value in quantity field it changes value to 0.it seems t is not checking first condition.
Upvotes: 0
Views: 65
Reputation: 5953
You need to convert those two values into number/integer, as you are comparing strings:
var avail = parseInt($('#available').val(),10);
var quant = parseInt($('#quantity').val(),10);
Upvotes: 1
Reputation: 3765
You are compare strings in your case. Use:
var avail = +$('#available').val();
var quant = +$('#quantity').val();
Upvotes: 1