Grow your CSS skills. Land your dream job.

jQuery .keypress(); event help!

  • # May 15, 2013 at 7:22 pm

    Hey, so I’m making an app where when you type text into the

    # May 15, 2013 at 7:39 pm

    jsfiddle works if you include jQuery.

    Preventing the letter ‘a’ to show is easy with `preventDefault()`. By the way, the letter a would be `01100001`.

    http://jsfiddle.net/tG8py/1/

    # May 15, 2013 at 7:45 pm

    Actually here’s an even better one with automatic keyCode conversion:

    http://jsfiddle.net/tG8py/2/

    EDIT: Actually use `this.value = keyCode;` instead of innerHTML, innerHTML bugs if you use backspace or something.

    # May 15, 2013 at 7:46 pm

    Thanks mate! Is there a way to make it so you can press it more than once?

    # May 15, 2013 at 7:47 pm

    Do you want to append new keycodes to the old one or replace the old one?

    # May 15, 2013 at 7:48 pm

    Ahh, I was just thinking that! I need to append(); pls. Thanks for helping me, I’m a beginner. ;)

    # May 15, 2013 at 7:50 pm

    Easy: http://jsfiddle.net/tG8py/3/ as long as the user doesn’t use backspace since backspace removes only 1 bit, would be nice if it removed 8 :)

    # May 15, 2013 at 7:52 pm

    Thanks a lot man!

    # May 15, 2013 at 8:23 pm

    No problem :)

    # May 17, 2013 at 1:50 pm

    If you want the backspace key to remove 8 characters only in that textarea, it’s not difficult using “.slice()“. http://jsfiddle.net/cyUs8/

    # May 17, 2013 at 3:29 pm

    I was already demotivated by backspace not triggering a keypress, nice to see keydown does work :)

    # May 17, 2013 at 8:01 pm

    From what I read in my brief research to get that working, “keypress“ is only for character keys, while “keydown“ will register function keys. ;)

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".