Chained Selects Step-by-step: Set up the callback function
As we just mentioned, the initListGroup() call has the following syntax:
initListGroup("list-group-name", form-select-1, form-select-2, ..., form-select-N, "cookie-name", callback-function);
The "cookie-name" parameter and callback-function parameter are optional, their order in the initListGroup() call doesn't really matter as CS will check the type of the parameter to determine what parameter is given, for example, 'cookie-name' would be a string and callback-function would be a JS function object.
Once set up, a callback function will be called each time we pick an option from a select list, and the callback function will receive four parameters:
A list group can be re-used by different sets of select lists, thus the instance order parameter is given to tell which instance is being used by the select list. If the select list is a multiple-choise list, then the selected value parameter will contain option values separated by commas, otherwise, it's the selected option value.
So, to set up a callback function, we can have something like:
and make the initListGroup() call like this:
<body onload="initListGroup('vehicles', form-select-1, ..., form-select-N, checkLists);">
Click [ here ] to see a demo page.
The callback function is like the onchange handler of a select list except that it's called for each list within the select list set that implements a list group. If a select list has an onchange handler, the handler will be called after the callback function.
Click [ here ] to see another demo page.
# # #