This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Multiple Javascript commands form onClick Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Multiple Javascript commands form onClick" Watch "Multiple Javascript commands form onClick" New topic

Multiple Javascript commands form onClick

Judy Herilla
Ranch Hand

Joined: Jan 05, 2001
Posts: 89
Within an onClick, is it possible to run many Javascript commands?
I have...
<A HREF="#ABC" onClick="'http://pest/SP/VG?PID=PO_MTD_Desc.html','MetricLocation2', 'scrollbars=no,menubar=no,width=400,height=100')">
This helps me get a pop-up window...but I woudl like to ensure it gets the focus, such as when it has been minimized. I know that if I did
newWindow =
newWindow.focus() that this would work, ut I am not sure how to fit this into the submit onclick.

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
That's why JavaScript lets you define functions:

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You can also put multiple javascript commands into an HTML element by using ';' to separate them, like this:

but I prefrer Frank's solution, as it makes for more readable script.
[This message has been edited by Bodie Minster (edited May 09, 2001).]
Judy Herilla
Ranch Hand

Joined: Jan 05, 2001
Posts: 89
I had found your solution before I read both of your responses.
I like it because the portal framework I am using is tricky with scripts, and using the semicolon is simple and straightforward!
Thanks to both of you!!
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Of course, the other thing you can do is have the onClick call a function which in turn acts like a controller and calls multiple action functions.
I'm a soldier in the NetScape Wars...

Wait a minute, I'm trying to think of something clever to say...<p>Joel
I agree. Here's the link:
subject: Multiple Javascript commands form onClick
It's not a secret anymore!