What I want is to create my own function that will be bound as an event listener similar to how other event listeners (e.g., onclick) are set:
<input type="text" onMyFunction="alert('hi');" />
Is it possible and if so how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem you have is the browser does not realize it is a function in there. It is a string, the only way you can make it a function is to assign it as a function.
One way is either on document ready or onload, you query the document for elements with the attribute and reassign it.
HTML
JavaScript
Example running here
This code uses querySelectorAll which is not supported in all browsers.