javascript - Detecting each character inputed in field and run conditionals -
i building web app. believe easiest if try explain want user experience before ask question.
i want user go on site , begin type in text field. when each character inputted, want run conditional statement on character decided if should added text field. if character inputted not 1 want, character isn't added.
i have validations in model after text submited, want real time. i'm guessing relates javascript , not comfortable enough in coding know search for/research. can assist me in (tutorials, concepts, etc)?
thank taking time read this.
you can preventdefault
method on event object passed keydown event. tells browser not preform default action (which on text field appending letter field).
here implementation using jquery brevity, can implement same functionality in pure javascript well:
$('input').on('keydown', function(event) { // event.which character code if ( /* condition */ ) event.preventdefault(); });
and here fiddle example cannot type letter a: http://jsfiddle.net/354xj/
Comments
Post a Comment