This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "onClick() doesn Watch "onClick() doesn New topic
Author

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

Kanan Jariwala
Greenhorn

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
thanks
kanan
Sid Sharama
Greenhorn

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

regards,
sri
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
 
subject: onClick() doesn't work for Image, any work around!!
 
Similar Threads
tracking links in a db
Page displaying in IE6 and older versions but not in Higher versions, chrome and firefox also.
Getting "Unspecified" Java Script Error When trying to save a File.
Using onclick and ondblclick with setTimeout
Cannot find the problem in the code