How can I pass the right variables for the map on the inner click event? Essentially I have information that I pass to a function fooFunc
using a map bound to a click event. I generate the click functions in the loops because there are many objects they need to be generated for.
The map is complicated because I need to pass some things on the object and some things that the user selects.
for (i = 0; i < providers.length; i++) {
var tNeeded = $("#select"+i).val();
var type = $("#select"+i).find('option:selected').text();
$("#select"+i).on("change", function() {
tNeeded = $(this).val();
type = $(this).find('option:selected').text();
$("#target"+i).click({timeNeeded:tNeeded, timeType:reason, objectId:object[i].id}, fooFunc);
});
$("#target"+i).click({timeNeeded:tNeeded, timeType:reason, objectId:object[i].id}, fooFunc);
}
The definitions outside the change event are in case the user clicks the target without changing anything in the select box. Right now when the change event is triggered the objectID takes the last object's ID instead of the ID associated with the target click. How can I pass this ID along with the change function?