Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > href and onClick

Reply
Thread Tools

href and onClick

 
 
Regena
Guest
Posts: n/a
 
      02-06-2006
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?

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      02-06-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASE HREF and A HREF="#" onclick="..." Vincent van Beveren Javascript 2 07-06-2006 08:33 AM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
onClick method question (this.href and document.location.href) yogesh.bhardwaj@gmail.com Javascript 2 02-03-2005 02:38 PM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM
Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src Soren Vejrum Javascript 4 07-05-2003 01:47 PM



Advertisments