10

How to set default keyboard layout for input boxes, for example when the page gets loaded, we can type in an input text with another keyboard language else than English?

7
  • ??? plase explain better your problem explaining the whole situation and environment you work in. Commented May 27, 2012 at 10:06
  • Are you talking about, for example, virtual keyboards on touch devices? Commented May 27, 2012 at 10:08
  • No i just try to prvent user to pressing ctrl +shift to change the language,ijust set a defualt keyboard layout for an input box Commented May 27, 2012 at 10:09
  • 1
    @Pierre :) look at answer i configure the meta information and use the lang attribute , it work perfectly for me ;) Commented May 27, 2012 at 10:13
  • if it worked, please check the holo tickbox next to the answer, thanks Commented May 27, 2012 at 10:14

2 Answers 2

10

I'd think about the lang attribute. But this is meta-information, I'm really not sure the browser will do anything with it. Never tried it myself.

<input lang="is" ...>
Sign up to request clarification or add additional context in comments.

2 Comments

It does not affect keyboard settings at all.
I tried it in codepen, made an input with lang="en" and lang="ru", i have both English and Russian in gboard on Android, and it had no effect either in Firefox for Android or Chrome for Android. I see that duolingo (native app) manages to hint which language to use for text input but maybe that's not yet available via Web APIs. It's a shame, it's super useful when creating language apps
-1

I think that it's possible to catch a keyCode of the button, that was pressed, with javascript and then replace the symbol to the appropriate symbol from array.
This code helps to understand how to catch a keyCode (it does not depend on keyboard language)

<form>
Char: <input type="text" id="char" size="15" /> Keycode: <input type="text" id="keycode" size="15" />
</form>

<script type="text/javascript">

var charfield=document.getElementById("char")
charfield.onkeydown=function(e){
var e=window.event || e
document.getElementById("keycode").value=e.keyCode
}

</script> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.