Tuesday, December 03, 2013

jQuery Change Event, by default


I had a dropdownlist, on select of a value, will trigger a display of a table of contents, through some Knockoutjs binding.


As usual I placed a change event for the pastEventsYear dropdownlist, as:
 $("#pastEventsYear").change(function () {
            $('select option:selected').each(function () {               
                pastEventsViewModel.eventYear($(this).text());
                pastEventsViewModel.getPastEvents();
            });
});
Now, as you see, it is a "Change" function. Even if the default value (2012, in this case) is set on load of the page, the table contents do not display. So, I set the value of the "pastEventsYear" purposefully:
$("#pastEventsYear").val('2012');
It should have worked. But it didn't. All I had to do was:
$("#pastEventsYear").val('2012').change();
This triggered the change event.

No comments:

Post a Comment

Cookies, anyone?

  Our application started having integration issues early March this year. Did I say that was intermittent? To add to our confusion, we coul...