Loop :
var aInputs = document.getElementsByTagName("input");
for (var i = 0; i < aInputs.length; i += 1)
{
if ()
{
aInputs[i][] = ValidateChangeFunction;
aInputs[i][] = ValidateKeyPressFunction;
aInputs[i][] = ValidateFunction;
}
}
Validation (Not sure what all you need, so i threw in the whole object from an old js file of mine) :
var KeyCodes =
{
IsSpecial : function(oEvent) { return oEvent.ctrlKey || oEvent.altKey; },
IsActionKey : function(oEvent) { return KeyCodes.IsEditKey(oEvent) || KeyCodes.IsCtrlCommand(oEvent); },
IsNumber : function(oEvent) { return KeyCodes.IsActionKey(oEvent) || (((oEvent.which >= 48 && oEvent.which <= 57) || (oEvent.which >= 96 && oEvent.which <= 105)) && oEvent.shiftKey == false); },
IsDecimal : function(oEvent) { return KeyCodes.IsNumber(oEvent) || ((oEvent.which == KeyCodes.PERIOD || oEvent.which == KeyCodes.NUMPAD_DECIMAL) && oEvent.srcElement.value.indexOf(".") == -1); },
IsEditKey : function(oEvent)
{
var bIsEdit = false;
if (this.IsSpecial(oEvent))
return true;
switch (oEvent.which)
{
case this.ENTER :
case this.NUMPAD_ENTER :
case this.BACKSPACE :
case this.TAB :
case this.PAGE_UP :
case this.PAGE_DOWN :
case this.END :
case this.HOME :
case this.DELETE :
case this.INSERT :
case this.LEFT :
case this.RIGHT :
case this.UP :
case this.DOWN :
bIsEdit = true; break;
default :
bIsEdit = false;
}
return bIsEdit;
},
IsCtrlCommand : function(oEvent)
{
var bIsCtrlCommand = false;
if (oEvent.which == 17)
return true;
else if (oEvent.ctrlKey)
switch (oEvent.which)
{
case 65:
case 67:
case 70:
case 83:
case 86:
case 88:
case 90:
bIsCtrlCommand = true; break;
default :
bIsCtrlCommand = false;
}
return bIsCtrlCommand;
},
Display : function(oKeyCode) { return oKeyCode ? String.fromCharCode(oKeyCode) : ""; },
ESCAPE : 27,
ENTER : 13,
NUMPAD_ENTER : 108,
BACKSPACE : 8,
DELETE : (IsKHTML() ? 127 : 46),
INSERT : 45,
END : 35,
HOME : 36,
PAGE_DOWN : 34,
PAGE_UP : 33,
SPACE : 32,
TAB : 9,
NUMPAD_DECIMAL : 110,
PERIOD : 190,
COMMA : 188,
UP : 38,
DOWN : 40,
LEFT : 37,
RIGHT : 39,
NUMPAD_ADD : 107,
NUMPAD_DIVIDE : 111,
NUMPAD_MULTIPLY : 106,
NUMPAD_SUBTRACT : 109
}