Changing function parameters for onkeypress event according to source id
- by DarRay
I want to assign a function according to their id to all the input fields in a webpage. To do i wrote below code but all the input fields are running keyPress with same parameter..
:(
///////////////////Checks all available 'text' 'input's////////////////////
var inputs = document.getElementsByTagName('input');
var cnvtrInput = new Array();
for (var index = 0; index < inputs.length; index++) {
if (inputs[index].type == 'text') {
cnvtrInput[index] = new converter(inputs[index]);
inputs[index].onkeypress = function() {return keyPess(cnvtrInput[index])};
}
}
//index--;
With the last commented statement i found that the passing element of keyPress is the last value of index;
Finally i tried same with textareas but failed...