onkeypress event in javascript not showing the unicode(hindi/remingtongail) character it is only alerting 'r' on pressing a key.
i am using hindi indic input 3 toolbar to type in laptop.
my javascript code is

function validate(){
var string=event.key;
c = string.charCodeAt(1);
var xyx=String.fromCharCode(c);
alert(xyx);
}

My html text area code is

<textarea onkeydown="validate()"></text area>

Recommended Answers

All 3 Replies

To me it looks as if the keydown event picks up the one key so it performs as coded.
Reference: https://www.w3schools.com/jsref/jsref_charcodeat.asp , https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

There is also a design issue here where it looks like it fires on just key down and does not collect all the keystrokes.

Read and see how https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key works.

Per Mozilla documentation:

The keydown event is fired when a key is pressed. Unlike the keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.