How can I simulate a keypress of the "right arrow" key to an input, using vanilla javascript?
I have an input and a button. I want the button to trigger a keydown for the "right arrow" key on the input.
<input id="myInput" type="text">
<button id="myButton>Click Me</button>
Basically, the end result should be :
- Click the button
- Cursor moves one place to the right (because we triggered a keydown press)
I have tried these solutions but they don't work:
Is it possible to simulate key press events programmatically?
https://elgervanboxtel.nl/site/blog/simulate-keydown-event-with-javascript