Posts Tagged ‘Web’

How to fire event from javascript (Dynamic)

August 13, 2010 Leave a comment

I had a requirement to call onchange event of a select box (combo box) from JavaScript and the function has an input param as event. I found one article which helped me to achieve this for one of my clients mobile web site (Land Rover UK), when I was working at

The article link is Firing Javascript Events (like onchange)

Here is the code which I had to change a little bit to fit in my code:

function fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);

Here is the code for how to call this method:


Thanks to Jehiah

Categories: Browser, HTML, JavaScript Tags: , ,