Skip to content
Advertisement

What is the best way to make these buttons insert specific text into a text field?

I’ve made a virtual keyboard that has Russian characters and Latin characters. I want to make each character key on the virtual keyboard (.keyLetter) insert the Russian character (.primary) into the text field.
Additionally, I want to make each physical keyboard keypress activate the corresponding buttons onscreen, so that the user can type by clicking the onscreen keys, or by using their physical keyboard.
I want to print the character that is already written in the .primary div in order to avoid creating a unique function for every single key.
I’m very new to JavaScript, so please go easy on me. I’m just trying to find the best solution.
CodePen Link

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You do not have anything with id=”keyLetter” – you have a class on each.

You need to delegate.

I implemented the capslock too

I would personally not put divs in a button. Instead style the buttonFlexWrapper as a button

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement