Pergunta

I want to make my own virtual keyboard using JavaScript.

Please tell me the syntax how to add characters to a TextBox. Adding the first character is easy but adding the second one I am unable to do.

Anybody please give a hint/logic to add text to textbox on keypress.

Foi útil?

Solução

What Teneff said is the beginning.. this following code will be a hint for you..

<form name="virtual">
<input type="text" name="text"/>
<input type="button" onclick="a()" value="a" style="border:none;"/>
</form>
<script type="text/javascript">
 function a(){
    document.forms["virtual"]["text"].value += "a";
}
</script>

Outras dicas

1: Get all fields that will be able to write inside using the virtual keyboard

2: Attach an onfocus event to each field to know which was the selected field

3: After pressing the key on the keyboard add the letter to the value and return the focus to the field

THIS is a simple example I've wrote

If the issue is that the character is being overwritten, make sure you're adding the next character to the textbox rather than simply overwriting it. Ie if your textbox contained "a"

textbox.value += 'b'; // would result in "ab"
textbox.value = 'b'; // would result in "b"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top