Christian Graf
Christian Graf

Reputation: 406

Getting the sender of an event?

How can I get the sender of an onSubmit event in any browser? Or at least in FF and IE? Esp. as event.srcElementin IE seems to be the target? Well, isn't there anything like explicitOriginaltarget in browsers other than FF?

I'm looking for any solution in pure javascript, no JQuery.

What I want to do: I've got a form. And depending on the sender I want to do differnt 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;
}

Upvotes: 5

Views: 20742

Answers (1)

Wood
Wood

Reputation: 1766

Here you have a function. You just need to evaluate wich 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

Upvotes: 7

Related Questions