href and onClick

R

Regena

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?
 
R

Randy Webb

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top