I'm writing a Javascript library to monitor how the user interacts with form fields. It will have to monitor multiple events for a given element, so I can't use an onblah handler.
I would like the HTML author to decide what fields are monitored. I thought I'd offer something like this:
<script src="formWatch.js"></script>
<form ...>
<textarea name="blah" onload="watch(this)"/>
<input type="submit" value="Submit" />
</form>
Then watch()
would register various event handlers on the element. But it seems onload
only fires on elements which load resources?
What is a good pattern for allowing the HTML author to decide what elements a Javascript library will pay attention to?