1There's a couple of ways you can do this. If the onchange listener is a function set via the element.onchange property and you're not bothered about the event object or bubbling/propagation, the easiest method is to just call that function:
2
3element.onchange();
4If you need it to simulate the real event in full, or if you set the event via the html attribute or addEventListener/attachEvent, you need to do a bit of feature detection to correctly fire the event:
5
6if ("createEvent" in document) {
7 var evt = document.createEvent("HTMLEvents");
8 evt.initEvent("change", false, true);
9 element.dispatchEvent(evt);
10}
11else
12 element.fireEvent("onchange");