By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

href and onClick

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.