I have a dilemma between 2 preferred methods of operations:
-
Attaching an event listener when the body loads using jQuery:
$(function(){ ....that will catch the form event.
-
adding
onblur/onkeyupto the HTML code and create JS function definition.
What would be better practice?
It depends on your particular requirements, but in general I would say event listeners are better practice as this seperates your HTML from your javascript logic.
Therefore if you add a new HTML element, this will automatically use your event listener, rather than you having to explicitly set the event call each time.