Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2003, 01:50 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Anchor Tags and the onClick event

Hi guys, I've encountered a problem and I would like some advice and informatiuon on it if possible

I have a couple of Anchor tags on my site surrounding images, tehy have the onClick event in them which runs a function, eg...
Code:
<a href="#" onClick="myFunc();"><img src="image.jpg"></a>
Now this worls fine in all browsers except IE5 and Opera, doesd anyone have anmy cluse as to why, I've done some searching but have found no news on it.

I've found that if I Change the image to be a button...
Code:
<input type="image" onClick="myFunc();">
This works fine and I've got no problem using this method, hell it would probably work if I used...
Code:
<a href="javascript:myFunc();"><img src="image.jpg"></a>
But I'm just interested in why my original method didn't work, any clues out there?

Blaise
 
Old June 13th, 2003, 02:28 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The onclick event handler needs to supress the links default behavior to navigate to what's specified in the href attribute.
It should be like this:

<a href="#" onClick="myFunc(); return false"><img src="image.jpg"></a>


/Robert
 
Old June 15th, 2003, 12:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

i'm not sure whether anchors support onClick event handler... here's how you can go around....

<a href="javascript:myFunc(); return false;"><img src=image.gif"></a>



the genuine genius
 
Old June 16th, 2003, 01:47 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, they support the onClick event handler...
See correct code below.


/Robert
 
Old June 16th, 2003, 04:58 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you put the event to him onClick, has preference href that you put to him. So that he makes case to which you wish you would have to put: there <a href="javascript:void(null) "onclick="myFunc()">
Being able even to call same to your function
<a href =" javascript:void(null);myFunc()">





Similar Threads
Thread Thread Starter Forum Replies Last Post
onClick and go to anchor #something Parabolart Javascript 7 November 28th, 2006 06:45 AM
really stupid problem with anchor tags thenoseknows ASP.NET 2.0 Basics 3 August 31st, 2006 09:34 AM
Generating anchor tags swwallace XSLT 3 March 8th, 2006 03:05 PM
onClick Event mateenmohd Javascript 4 December 16th, 2003 01:08 AM
Anchor Tags don't work on iMac DenimDog HTML Code Clinic 3 October 30th, 2003 03:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.