How to control cursor movement in a textarea tag using buttons... | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

How to control cursor movement in a textarea tag using buttons...

How do I control the cursor in a <input type="text"/> tag using other buttons... Like the "<" and ">" buttons in the code below?šŸ‘‡šŸ‘‡ https://code.sololearn.com/WWHai17dPP8p/?ref=app

4th Jan 2021, 10:06 AM
...
... - avatar
5 Respostas
+ 2
It's tricky: as soon as user ciick on button, the text zone with cursor lost focus, so you cannot know the last cursor position... The only workaround would be to implement and handle yourself the cursor display/position/movement plus keyboard inputs... that's not impossible (advanced web editor tends to use more or less this technic) but cannot be easy and fast done ^^
4th Jan 2021, 12:53 PM
visph
visph - avatar
+ 1
Set cursor on input element with focus method then use selectionStart and selectionEnd methods to control and set cursor position. https://code.sololearn.com/WV4O5fBs53Jc/?ref=app
4th Jan 2021, 2:17 PM
CalviÕ²
CalviÕ² - avatar
+ 1
Thanks CalviÕ² and visph
4th Jan 2021, 5:16 PM
...
... - avatar
+ 1
... then you need to build custom input with cursor, that is tricky.
5th Jan 2021, 5:02 AM
CalviÕ²
CalviÕ² - avatar
0
CalviÕ² is there any way to prevent the keyboard from coming up?
4th Jan 2021, 5:24 PM
...
... - avatar