In my source code, I have many examples similar to the following:
<input id="a" type="text" name="a" maxlength="40" onfocus="ThisOnFocus(this)" onkeydown="ThisOnKeyDown(this)" onkeyup="ThisOnKeyUp(this)" onblur="ThisOnBlur(this)"/>
Each input tag ends with those onfocus, onkeydown, onkeyup, and onblur calls.
What I would like to do is to indicate globally that all input tags call these functions for these events. Is this something that can be done in JavaScript? Thanks!
Edit: I tried to place this in a script section, and none of my functions are 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: In addition, it is not necessary to distinguish between input flags and text fields, but all these functions apply only to text fields.
source share