$("#searchType").on('change', function () {
var selectionAction = {
All: loadAll(),
Competitions: loadAll("competitions"),
Clubs: loadAll("clubs"),
Teams: loadAll("teams")
};
var selection = $("#searchType").find('option:selected').val();
selectionAction[selection]
});
See the above code. The idea is that when selection equals one of the properties in my object, then the corresponding function will be called.
e.g. when selection equals Competitions then we would invoke loadAll("competitions") function.
Instead what I am finding is that when it enters the onChange function that it invokes all functions.
What am I doing wrong here?
()after a function reference, the function gets called.All: loadAll(),calls the functionloadAlland assigns the return value to the propertyAll.