I'm looking to create a virtual keyboard event for tab using JavaScript. I've researched this topic and found some helpful answers, but I haven't been able to get it working properly. I know that JavaScript is an event-driven language and typically requires user input for key events, but I'm curious if it's possible to simulate a keyboard event through JavaScript.
function generateTabKeyEvent() {
var e = new KeyboardEvent("keydown", { keyCode: 9 });
document.getElementById("someTxtBox").dispatchEvent(e);
}
<input type="text" id="someTxtBox"/>
This function doesn't seem to work in IE8, and there are no visible errors. My goal is to trigger a keyboard event (tab) on the textbox whenever this function is called.
Source1, Source2. Any suggestions would be greatly appreciated.