// get element var elem = document.getElementById("some_dropdown"); // set selected option elem.selectedIndex = 2; // generate an 'onchange' event from 'elem' var event = document.createEvent("HTMLEvents"); event.initEvent("change", true, true); event.eventName = "change"; elem.dispatchEvent(event);
createEvent and dispatchEvent don’t work on IE 8 and earlier, although those browsers do have their own equivalents.
And that’s why God invented jQuery! (Check out jQuery.trigger().)
Comments are closed.