I'm giving a value to a textbox
and then giving focus to it.
document.getElementById('textbox').value="abcd";
document.getElementById('textbox').focus();
Then, I am creating a keyboard event and trying to fire the CTRL+A key combination (trying to select the text inside the textbox
) by writing the following code:
var myEvent = document.createEvent('KeyboardEvent');
myEvent.initKeyEvent("keypress", true, true, window, true, false, false, false, 0, 97);
document.getElementById('textbox').dispatchEvent(myEvent);
But the above code doesn't select the text inside the textbox.
How to select the text creating the keyboard event ?