Page 1 of 1

What key is pressed?

Posted: Mon Oct 07, 2013 1:00 pm
by dieter
Hello,
we try to write an event based JavaScript function. The function is bound to the "onkeyup"-event of a textbox:
ecc.dateChecker(this);

So the function is called after every keystroke. But in our function we have to know which key was pressed. Also we need to know, on which position in the field the cursor is.

Can you help us?

Dieter

Re: What key is pressed?

Posted: Mon Oct 07, 2013 1:23 pm
by Scott Klement
If you set your onkeyup event to the name of a JavaScript function (instead of setting it to the actual code to run) it will call that function and pass two parameters:
  1. The browser's "event" object. This has a subfield for the key code that you can use.
  2. A reference to the DOM element that the event fired in. You can pass this to our getCursorPosition() API to get the cursor position.
More info on the onKeyUp event:
http://www.profoundlogic.com/docs/displ ... eyup+event

More info on the getCursorPosition() API:
http://www.profoundlogic.com/docs/displ ... lement+%29

Re: What key is pressed?

Posted: Tue Oct 08, 2013 7:54 am
by dieter
Hello Scott,

thank you very much. It is exactly what i am looking for.

Dieter