Getting the event sender?

How can I get the onSubmit event sender in any browser? Or at least in FF and IE? Especially how event.srcElement in IE seems to be the target? Well, is it anything like explicitOriginaltarget in browsers other than FF?

I am looking for any solution in pure javascript, without jQuery.

What I want to do: I have a form. And depending on the sender, I want to perform different actions in the onSubmit(event) routine.

What I got in my init function:

 var top_most_form = document.getElementById("upper_menu_form"); top_most_form.onsubmit=function(event){ var target = <apparently magical things have to happen here>; if ("upper_menu_form" == target.id) { AddSpinner(); AddStarttimeToForm(); AddThruputToUpperForm(); } else { return false; } 
+4
source share
1 answer

Here you have a function. You just need to evaluate which parameter is present in your event object.

 function getTarget(e){ e=e||window.event; return (e.target||e.srcElement); }; 

See: jQuery - how to determine which link was clicked

+5
source

Source: https://habr.com/ru/post/1493475/


All Articles