i have the following input tag:
<input id="item_amount" type="text" id="item_stk" placeholder="1" value="" class="input-small" placeholder="" style="float: left;">
now to make sure that this input fields value is less than a certain amount i made the following Jquery function:
var max_amount = $('#max_amount').val();
$( "#item_amount" ).keyup(function() {
if($(this).val() > max_amount){
$(this).val( max_amount);
}
});
Now max value is set to 2
if i write 4 in the input field it correctly returns the value to 2.
However if start by writing 1 then 2 then 3 then 4 ect ect ect. then it never gets into the if statement and resets the value.
ie. the value of the input field is now 1234 (which is far more than 2).
So what am i doing wrong?