Search code examples
javascriptselectdom-eventsonchange

Onclick on option tags if onchange is not enough


I have two selects A and B which trigger on onchange event the same ajax request which rewrites some content area. If I click on the option A in select A onchange works well and ajax call rewrites the content. Then if I click on the option B in select B this ajax call also rewrites the content. And here is the problem. If I then want to select option A in select A which remained selected from the first action it does not triggers onchange event (cause is already selected).

How to solve it if click event is not supported on option tags? I tried to deselect option tag after onchange like

complete: function()
{
    $(this).prop("selected", false);
}

but this also does not triggers onchange event even if option is deselected. How to solve it? Thanks.

Example https://jsfiddle.net/h7cokr6b/1/


Solution

  • complete: function()
    {
        $(this).prop("selectedIndex", 0); // It has to be default selected value's index.
    }