javascript - Catch input earlier than onChange and preferably only numbers -


i have table of input fields. form used inexperienced users want prepared worst.

i have created code highlight table row it's input field has changed. downside here code triggered after user has clicked outside inputfield.

what looking achieve following.

  • as user types in something, triggered, after every digit, enter/backspace, etc. event highlight table row. later on want extend function automatically save form locally, figure out code later on.
  • secondly, price form, great if user can only type in numbers

the browsers using have full html5 , css3 support, , javascript engine use newest version of jquery.

ps. if there downsides on implmenting please let me know also.

use keyup event, value of input have been updated time event fires can change value before user blurs element.

update

you can limit input numbers using regular expression:

//bind `keyup` event `input` element(s) $('input').on('keyup', function () {      //replace value of input digits in it's value     //note method works if user pastes block of text input     this.value = this.value.replace(/[^0-9]/gi, ''); });​ 

here demo: http://jsfiddle.net/bkstg/1/


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -