function updateColourDropdown(url) {
// Remove handlers on #selectList
$("#selectList").unbind();
// Post to URL specified in the parameter, serializing #fruitForm
$.post(setUniqueParam(url), $("#fruitForm").serialize(),
// Run this on success
function(data) {
// Assuming `checkException` looks in the returned
// data to see if something went wrong.
if (checkException(data)) {
// Something went wrong; for each of #fruitDiv's children
// run the function that removes that child element, then
// at the end, put the data, which appears to be HTML,
// into #fruitDiv
$("#fruitDiv").children().each(function() {
removeElem(this);
}).end().html(data);
// Then set a new `change` event handler on #selectList
// that runs `updateColourDropdown, given the value of
// #fruitColourView. See Note 1.
$("#selectList").change(function() {
updateColourDropdown($("#fruitColourView").val());
});
// Then call this.
organiseAllocateTeams();
}
// Useless.
data = null;
}
);
return false;
}
Note 1: In reasonably current versions of jQuery I'd probably handle this with a handler that uses event delegation to avoid having to unbind/rebind repeatedly.
The question has nothing to do with Struts, and there's not too much going on that's particularly difficult to reason about.