I know it's bad practice to put this on the global namespace. An alternative would be to make this function search for all inputs with a given class and apply the below logic to them when the document has loaded. Or to provide a different variable to this function all together. I imagine that users of this file will later it to suite their needs.