For strange reasons, I have to change the selected item in the drop-down list not through e.selectedIndex, but through the simulation of mouse events and keystrokes.
I tried the following:
//e = the dropdown e.focus(); //my custom function to fire mouse events. This opens the dropdown. fireMouseEvent("mousedown", e); //firing the key press, tried it via keydown, keypress and keyup. Nothing works. var evt = e.ownerDocument.createEvent("KeyEvents"); evt.initKeyEvent("keydown", true, true, null, false, false, false, false, 40, 0); evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 40, 0); evt.initKeyEvent("keyup", true, true, null, false, false, false, false, 40, 40); e.dispatchEvent(evt);
Am I doing something wrong or is it impossible?
Thanks.
source share