dlanod
dlanod

Reputation: 9020

Chinese characters and the onkeypress event

Using Internet Explorer on Windows I have an onkeypress event detecting text entered into a text box. However when entering Chinese characters this event doesn't fire. Has anyone encountered this or have suggestions on working around this?

Upvotes: 12

Views: 4770

Answers (3)

liopic
liopic

Reputation: 153

Depending on the keyboard settings, writing a single Chinese character usually requires typing several keys. For example, 豈 can be written using a 4-key sequence (山一口廿), as you can see here: http://en.wiktionary.org/wiki/%E8%B1%88

You need to use an onchange event in this case (and also for Korean and Japanese!)

Upvotes: 1

Steve-o
Steve-o

Reputation: 12866

Google Suggest (autocomplete) polls the input for changes as the events are completely unreliable for Unicode. Browsers used to support mid-IME input events which was very nice for Japanese, but support quickly broke or was dropped.

Last time I check was 2006 though, so retesting is required. Here are my previous notes:

http://web.archive.org/web/20060220125639/http://fnjordy.cus.org.uk/auto/

Including non-resolved bug in Firefox:

https://bugzilla.mozilla.org/show_bug.cgi?id=286842

Upvotes: 5

hayesgm
hayesgm

Reputation: 9096

Based on this JSFiddle, it seems the keydown event does not fire as one might expect. I would use the keyup event (though, you'll still get partially entered characters).

From my experiment, I got:

  • An event for "ni" instead of 你
  • An event '你ha'
  • An event for 你哈 (since the alert killed my input to complete 'hao')

Basically, Windows and IE are not playing nicely with character input. I would suggest using the change event if it's possible in your framework.

Upvotes: 3

Related Questions