/ Published in: JavaScript
A browser friendly way to trigger an event on an element. This is just a simple snippet which doesn\'t really explain the detailed contents of an event object, but it gives an idea of the differences between specific browsers. This function will fire the onChange event for an element passed to it (say...a checkbox).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function FireOnChange(element) { if (element.onchange) { var e = null; if (document.createEventObject) { //ie e = document.createEventObject(); element.fireEvent('onchange', e); } else { //others e = document.createEvent('HTMLEvents'); e.initEvent('change', true, true); element.dispatchEvent(e); } } }