In html, can language input be changed based on ITEM?

You have a custom form containing numerous lines, similar to the following:

<h2>Parts of Body</h2> <div> English: <input name='body_en-1' /> &nbsp; Thai: <input name='body_th-1' /> &nbsp; Description: <input name='body_descr-1' /> <br/> ... </div> 

problem: killing users switching the keyboard back and forth between two languages ​​- many mistakes, many complaints.

anyway, what INPUT.focus() can switch the keyboard between languages ​​for the user?

+4
source share
2 answers

The direct answer ... No, you cannot.

What you can do is, you can emulate a different keyboard layout by matching different keyboard layouts with an English keyboard layout.

for example, you can use this for a Nordic layout:

  <input name="Swedish" type="text" onkeypress="convertToNordic(event, this);" onkeyup="doBackSpace(this);" /> <script> function convertToNordic(evt, handle) { switch (String.fromCharCode(evt.which || evt.keyCode)){ case '[' : handle.value += 'Γ₯';break; case ';' : handle.value += 'ΓΆ';break; case '\'' : handle.value += 'Γ€';break; default : handle.value += String.fromCharCode(evt.which || evt.keyCode); } } function doBackSpace(handle){ handle.value = handle.value.substr(0,handle.value.length-1); } </script> 

Here is jsfiddle

and you can work from there

0
source

No, and you don’t even know if any particular keyboard layout is available (for example, any specific layout for the Thai language). There are four layouts for Thai on my computer. I never included any of them, but if I did this and use the layout, the likelihood that it will be different from what you are trying to make me use.

Custom character input can be tricky, but you can't fix it while trying to set the keyboard layout. If you can set the layout in JavaScript (I think you cannot), you can seriously disrupt functionality when the user is used to a completely different location.

In some cases, an on-screen keyboard may solve part of the problem. For example, if users only need to enter a word or two in Thai and everything else is in English, you can embed a virtual keyboard with a Thai character (and possibly hide it until the field for Thai input is focused).

Technically, you can set the lang attribute for individual elements, for example, and that would be correct in principle, but in practice it hardly has any effect on anything now.

0
source

Source: https://habr.com/ru/post/1411044/


All Articles