javascript - How to get entered value after onkeydown? -
i'm trying new value of inputbox after entering each character if it's number. ajax in example below sends old value , not newly entered value.
for example, if value 1 , focused inputbox, deleted value , pressed 2, ajax send "1". need send "2"
html
<input type="text" class="quant-input" size="7" name="qty" value="1" onkeydown="change_qty();"/> javascript
function change_qty(evt) { var charcode = event.keycode if (charcode > 48 || charcode < 57) { jquery.ajax("page.php", { type: "post", data:'data='+$('.quant-input').val() }); return true; } else { return false; } }
the value isn't changed until keyup event. need use following instead:
onkeyup="change_qty();"
Comments
Post a Comment