for(var i=0; i<document.getElementsByName("my_name").length; i++) { document.getElementsByName("my_name")[i].onkeyup = function(i) { console.log(i); } }