I have the following code which attaches a function to events in x number of comboboxes (x will probably always = 4, but I do not want to hard-code this). I wish to pass the value of -i- to the function being attached as well as the value of -tempData-. In other words, I want the parameters in function to be the value, not a reference variable.
In the current example, I am using the hard-coded variable ci. This I want to be replaced by a literal created when the event handler is attached (the value of the loop variable i). Also, notice that I get the filter value in the event handler (assigned to the variable ct). I would like to replace this code with the value of tempData which would also be determined when the event is attached (it is the same value in this case, but it keeps the onChange event from having to do this each time it runs).
var props = {
col_0: “select”,
col_1: “select”,
col_2: “select”,
col_3: “select”,
btn_reset:true,
display_all_text: “-Show All-”,
on_filters_loaded: function(o){
//reset all filters
var slcIndexes = o.GetFiltersByType(o.fltTypeSlc, true); //o.fltTypeSlc = ‘select’
for(var i=0; i<slcIndexes.length; i++){
//this public method returns a filter DOM element by column index
var slcElm = o.GetFilterElement(slcIndexes[i]);
tempData = slcElm.options[slcElm.selectedIndex].text;
//window.alert(tempData + " " + slcElm);
tf_AddEvent(slcElm, ‘change’, onchangeFn=function(){
//ci is the column index for the column to filter on. ct is the new text from the combobox to filter on
var ci;
ci = 2;
var ct = tf_outputTable.GetFilterValue(ci);
tf_outputTable.ClearFilters();
//window.alert("ci= " + ci + " ct= " + ct);
tf_outputTable.SetFilterValue(ci, ct);
tf_outputTable.Filter();
}); //end tf_AddEvent
}
}
}
setFilterGrid(“outputTable”,props);