For strange reasons I have to change the selected element in a dropdownbox not via e.selectedIndex, but via the simulation of mouse and keypress events.
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 anything wrong or is this impossible?
Thank you.