href and onClick

Discussion in 'Javascript' started by Regena, Feb 6, 2006.

  1. Regena

    Regena Guest

    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?
     
    Regena, Feb 6, 2006
    #1
    1. Advertising

  2. Regena

    Randy Webb Guest

    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/
     
    Randy Webb, Feb 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    203,758
    Adrienne Boswell
    Jun 20, 2006
  2. Soren Vejrum
    Replies:
    4
    Views:
    762
    Lasse Reichstein Nielsen
    Jul 5, 2003
  3. saiho.yuen
    Replies:
    3
    Views:
    549
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    628
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    426
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page