onkeydown - Key Down Script
Activates an event handler when a control receives a key press.
Category
eventsSyntax
<xp:eventHandler event="onkeydown" attributes>content</xp:eventHandler>
Usage
For detailed event handler syntax, see eventHandler - Event Handler (property).To identify
the key, you can use the keyCode
property for thisEvent
.
Other useful properties are altKey
, ctrlKey
,
and shiftKey
.
Examples
This button has a client handler for theonkeydown
event. The client handler allows the
button to accept keystrokes, adding them to an input box if they are
0 through 9 and ignoring them otherwise.<xp:button value="Add keystroke" id="button1">
<xp:eventHandler event="onkeydown" submit="false">
<xp:this.script>
<![CDATA[var e = window.document.getElementById("#{id:inputText1}");
var k = thisEvent.keyCode;
if (k >= 48 && k <= 57) {
e.value = e.value + String.fromCharCode(k)
}]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>