File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes onClick() doesn't work for Image, any work around!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "onClick() doesn Watch "onClick() doesn New topic

onClick() doesn't work for Image, any work around!!

Kanan Jariwala

Joined: Jun 22, 2000
Posts: 17
Hi all,
In my requirement, i have more than one images(that act like buttons), when i click on any of the imgages,
1)onClick should get invoked
2)Within the onClick()Script some hidden Input Types are set dynamically
3)the form is then submitted.
Note: onClick() works in IE , but not in Netscape.
I am looking out for a solution that will work in both
Sid Sharama

Joined: Feb 06, 2005
Posts: 11
make image an href like
<a href="some action" onClick='dosomejavascript()'><img src='pic.gif'></a>
it should work javascript you can even change the image
by specifying a new src.

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
You have to be a little careful with making an image into a link. Some browsers will link to the specified URL as well as running the onClick.
The best solution I have found is to make the image into a link,
but link to a "javascript" URL. For example:

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: onClick() doesn't work for Image, any work around!!
It's not a secret anymore!