Custom selectbox trigger onchange event multiple times

We have implemented a jQuery selectbox plugin and created a custom trigger event to get the data when a selectbox is changed. For example, we use this to select the desired product attribute options in a Magento shop.

Everything goes well until we select an option which has already triggered in the same 'session'. Then nothing happens. How is that possible?

The trigger event:

Element.prototype.triggerEvent = function(eventName)
{
    if (document.createEvent)
    {
        var evt = document.createEvent('HTMLEvents');
        evt.initEvent(eventName, true, true);

        return this.dispatchEvent(evt);
    }

    if (this.fireEvent)
        return this.fireEvent('on' + eventName);
}

var global_select = '';

function customEvent(id, event) {
    global_select = id;
    $(id).triggerEvent(event);
    global_select = '';
}

The jQuery code:

jQuery('select').change(function(e) { 
    id = jQuery(this).attr('id');
    if (id && id != global_select)
        customEvent(jQuery(this).attr('id'), 'change');

    jQuery('select').each(function() {
        var id = jQuery(this).attr('id');
        if (jQuery(this).css('display') == 'none') {
            jQuery(this).selectbox('detach');
            jQuery(this).hide();
        } else {
            jQuery(this).selectbox('attach');
        }
    });
});

jQuery('select').each(function(){
    if (jQuery(this).css('display') != 'none') {
        jQuery(this).selectbox();
    }
});

Answers


We fixed this by changing the jQuery version from 1.10.2 to 1.8.2.


Need Your Help

opkg --force-downgrade - how does it work?

package package-managers opkg

I am trying to bring a package to an earlier version using opkg running this --force-downgrade opkg command, but it seems it doesn't behave like it should. Did this option work for anybody so far?...

How to open EditTextPreference on open preference screen

android edittextpreference

I want to open EditTextPreference when I open Preference screen. I try