Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OnClick & OnLoad

    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?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The event object has a property named "type".

    if (e.type == 'onload') ...
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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.

    Code:
    onclick="YourFunction("true")
    onload="YourFunction("false")
    
    function YourFunction(process1){
    
      if(process1)alert("Click")
      else alert("onload")
    
    }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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)">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •