468,316 Members | 2,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

href and onClick

hi,
I have an image and when a "href" associated with it. on href it
should go to "link1" for example and onClick I have to call a
javascript function.
the way I do is:
<a href = "link1" ><img src="something" name="something"
onClick="javascript function();"></a>
the way its working is onClick its performing the javascript function
but coming back to the original page on fully loading the page. how do
I do it in the right way?

Feb 6 '06 #1
1 4470
Regena said the following on 2/6/2006 8:54 AM:
hi,
I have an image and when a "href" associated with it. on href it
should go to "link1" for example and onClick I have to call a
javascript function.
the way I do is:
<a href = "link1" ><img src="something" name="something"
onClick="javascript function();"></a>
the way its working is onClick its performing the javascript function
but coming back to the original page on fully loading the page. how do
I do it in the right way?


What do you call "the right way"?

<a href="link1" onclick="return someFunction(this.href)">
<img src="..."></a>

And then have someFunction use the href passed to it as a parameter to
set the document.location property:

function someFunction(URLToUse){
//do whatever you want here;
document.location.href = URLToUse;
return false;
}

In the future, do not post pseudo-code, post actual code. function() can
not be the name of a function.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jez | last post: by
11 posts views Thread by Dana Smith | last post: by
14 posts views Thread by Brandon Hoppe | last post: by
4 posts views Thread by Jamie Jackson | last post: by
53 posts views Thread by usenet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.