@DokAug 29.2007 — #Depends on which scope you're using
If you're doing [CODE]window.onload = function() { // Get myfields somehow first for (s in myfields) myfields[s].onkeyup = myfunction(myfields[s]); };[/CODE] Then you're assigning the return value of myfunction as the onkeyup event handler which is probably not what you want
If you're doing [CODE]window.onload = function() { // Get myfields somehow first for (s in myfields) myfields[s].onkeyup = function() { myfunction(myfields[s]); }; };[/CODE] then you're creating closures and and onkeyup will always be executed with s having the last value of the for..in enumerating. Mr. Moo - please correct me here if I'm wrong ?
If you're doing [CODE]window.onload = function() { // Get myfields somehow first for (s in myfields) myfields[s].onkeyup = function(){myfunction(this)}; }; };[/CODE] then 'this' will refer to the window/global object everytime the onkeyup event is fired and you're still creating closures.
I'm guessing you want to do something like this [CODE]function fieldOnKeyUp() { // Do whatever. 'this' is refering to the HTML element which fired the event // Alert the value of the field alert(this.value); }
window.onload = function() { // Get myfields somehow first for (s in myfields) myfields[s].onkeyup = fieldOnKeyUp; };[/CODE]
@Mr_MooAug 29.2007 — #Dok, you are right (and hence my original post is incorrect; I need to drink coffee before I post on the Internet). Kor's solution (and yours) is correct.