Instead of looping through this 44 times, why not delegate the event? attach a single listener, and check if the id matches a given pattern
document.body.addEventlistener('keypress', alphaFilterKeypress, false);
You'll have to change the function definition - adding this check:
function alphaFilterKeypress(e)
{
e = e || window.event;
var target = e.target || e.srcElement;
if (!target.id.match(/alpha[0-9]+/))
{//don't handle the event
//event was fired on an element with another (or no) id
return e;//don't handle it here
}
//an element with id alpha[number] fired the event
//handle the event
}
As you can see from on this previous SO question the type of "key" event you're using is important. Where the keypress
event does not pick up on keys like backspace, control etc... you might want to prefer using the keydown
event.
Play around with it, and work out which event suites your needs the best