Platform SDK: Web Telephony Engine

The onkeypress Event

The onkeypress event is fired each time the user enters data into the entry field created by a TEXTAREA element or by an INPUT element whose TYPE is text. The WTE fires the event each time the user presses a DTMF key. A graphical Web browser fires the event each time the user enters a character by means of the keyboard.

The onkeypress event gives you a chance to examine or change a character before it is entered into the entry field. For example, the onkeypress event handler for a credit-card number field might check each character and, if it is a digit, let it through unchanged. The handler could discard nondigits, such as the pound key (#).

You could also designate a special key, such as the star key (*), to have special meaning. For example, your application might say, "Enter your credit card number. If you press an incorrect digit, press the * key to cancel the previous digit." Your onkeypress event handler would check for the * and, when it arrives, edit the characters entered so far, deleting the last character that the caller entered.

An event handler for the onkeypress event can change the value of a key entry by using the Event object (External.Event). For example, suppose you wanted to change all star (*) keys to zero (0) characters. Your event handler can use the Keycode property of the Event object to find out the ASCII value of each key pressed and, if it is 42 (ASCII *), change the value of the Keycode property to 48 (ASCII 0). For example:

<script Language="VBScript" For="acctnum" Event="onKeyPress">
If External.Event.Keycode = 42 Then
    External.Event.Keycode = 48
End If
</script>

To have the WTE ignore the digit that was pressed, set the Keycode property to 0.