my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes onclick two function calls Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onclick two function calls" Watch "onclick two function calls" New topic
Author

onclick two function calls

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
Is it possible/what syntax to execute two javascript functions from the onklick event handler?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

If you're doing this under script control (I prefer to keep all behavior out of the HTML markup):


This should give you enough of a clue to figure out how to declare it in HTML markup if that's what you're doing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

P.S. Of coures you'll need to deal with IE's window.event nonsense if the Event instance is important to you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

P.P.S. With the DOM Level 2 Event Model, you can assign as many listeners to a DOM element as you like, but IE doesn't support it. Always the life of the party, IE has its own proprietary API. So most people just use the DOM Level 0 Model (what's demonstrated in the previous posts).

Employing a library such as jQuery or Prototype hides all (or at least most) of the event handling browser differences from your code.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: onclick two function calls