Assigning onkeyup event to multiple objects at once <p>I am working with qualtrics and I am trying to customize their matrix control. I am trying to loop through a matrix with 8 rows and 4 columns where each cell contains a textbox and assign each textbox an onkeyup event like so: </p> <pre><code>for (var j=1; j&lt; 9; j++){ row_txt[j] = []; for (var k=1; k&lt;5; k++){ txt1= $('QR~QID2~'+j+'~'+k); txt1.onkeyup=function(){alert(j+','+k);}; } } </code></pre> <p>However, the onkeyup event returns "9,5" for each textbox changed. Why isn't it displaying the correct indices? How can I assign the same onkeyup event to multiple objects with the corresponding parameters j and k ?</p> <p>Thank you </p>