...

View Full Version : OnClick & OnLoad



aiya
01-13-2004, 05:57 PM
Hi all,
I have Onclick and Onload events which are calling same javascript function. How is it that inside the javascript I can differentiate that it is called by Onclick or Onload?

Roy Sinclair
01-13-2004, 07:34 PM
The event object has a property named "type".

if (e.type == 'onload') ...

A1ien51
01-13-2004, 07:38 PM
Basic idea of what you can do

You can put a variable,string,bolean in it and pass it to the function so you can figure it out.



onclick="YourFunction("true")
onload="YourFunction("false")

function YourFunction(process1){

if(process1)alert("Click")
else alert("onload")

}


Eric

glenngv
01-14-2004, 04:31 AM
Originally posted by Roy Sinclair
The event object has a property named "type".

if (e.type == 'onload') ...

the event type values doesn't start with on
the values are load, click, mouseover, etc...

function blah(e){
alert(e.type)
if (e.type=='load') ...
}
...
<body onload="blah(event)" onclick="blah(event)">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum