Capture keypress inside a textarea

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hans

    Capture keypress inside a textarea

    How do I capture the keycode inside a <textarea> in NN6+ and IE5.5+? I don't
    want to add add document.keyPre ss function because I only want this to
    occure when a specific textarea is selected and not fire for every keypress
    in the entire document.

    <textarea onkeypress="cap tureKeys();"... .

    but I cannot get a reference to the current event so i can ask for the
    keyCode. In IE I can check the event.keyCode inside my function captureKeys
    but this is not possible in NN6+.

    Regards
    /Stefan


  • Martin Honnen

    #2
    Re: Capture keypress inside a textarea



    Hans wrote:

    [color=blue]
    > <textarea onkeypress="cap tureKeys();"... .
    >
    > but I cannot get a reference to the current event so i can ask for the
    > keyCode. In IE I can check the event.keyCode inside my function captureKeys
    > but this is not possible in NN6+.[/color]

    Simply use
    <textarea onkeypress="ret urn captureKeys(eve nt);"
    and then
    function captureKeys (evt) {
    var keyCode = evt.keyCode ? evt.keyCode :
    evt.charCode ? evt.charCode : evt.which;
    if (keyCode == ...) {
    // cancel key:
    if (evt.preventDef ault) {
    evt.preventDefa ult();
    }
    return false;
    }
    return true;
    }

    --

    Martin Honnen


    Comment

    Working...