[jQuery] Attaching a jQuery event to a dropdown in an ASP.net Repeater?

[jQuery] Attaching a jQuery event to a dropdown in an ASP.net Repeater?


Hi,
I've got an ASP.net repeater which has an unknown number of rows, that
I'm passing as a variable into the client-side code. Each repeater
item has two dropdowns in it, one of which I need to attach to a
jQuery event to create a cascading dropdown.
I've put the change(function() { into a for..next loop, along with the
target control. It's not pretty, but it seems logical. Problem I
have is whenever the function is called, the ID of the target control
is the max value of the loop + 1.
Why is my loop variable behaving like a reference type instead of a
value type? Why is it even in scope outside the loop? Alternatively,
is there a better way to do this?
The code:
var rows = 4; // this is populated from the server code
for (iLoop = 0; iLoop<rows; iLoop++) {
$('#ctl00_repCBSkills_ctl0'+iLoop+'_ddlSkillCategory_ID').change
(function() {
PopulateSubSkill(
'ctl00_repCBSkills_ctl0'+iLoop+'_ddlSkillSubCategory_ID',
$('#' + this.id).val()
);
});
}
function PopulateSubSkill(target, var) {
alert(target); // always returns
'ctl00_repCBSkills_ctl05_ddlSkillSubCategory_ID' (note the 5)
}
Thanks in advance.
Duncan