I have many instances similar to the following in my source code:
<input id="a" type="text" name="a" maxlength="40"
onfocus="ThisOnFocus(this)" onkeydown="ThisOnKeyDown(this)" onkeyup="ThisOnKeyUp(this)" onblur="ThisOnBlur(this)"/>
Every input tag ends with those onfocus
, onkeydown
, onkeyup
, and onblur
function calls.
What I'd like to do is specify globally that all input tags call those functions on those events. Is that something that's possible to do in JavaScript?
Edit: I have tried placing this in the script section and none of my functions are being called:
document.onload = function() { var inputs = document.getElementsByTagName('input');
for (i = 0; i < inputs.length; i++) {
inputs[i].onfocus = ThisOnFocus;
inputs[i].onblur = ThisOnBlur;
inputs[i].onkeyup = ThisOnKeyUp;
inputs[i].onkeydown = ThisOnKeyDown;
}
}
Edit: Also, it may not be important to distinguish between input checkboxes and textfields, but these functions all pertain to just the textfields.