Results 1 to 6 of 6

Thread: Cancel href via an onclick

  1. #1
    Join Date
    Mar 2010
    Posts
    63

    Cancel href via an onclick

    I have a link created by ASP.NET that is used to submit my form -

    <a href="javascript:generatedfunction();">Click Me</a>

    I desired to be able to trigger an event on submit of the form. However since the form got submitted through javascript, I could not just associate the onSubmit of the form (did not be in function ) but I was able to insert my own generated function that triggers first in the onclick-

    <a onclick="myfunction();" href="javascript:generatedfunction();">

    And it is working fine now .So I wanted to ask that how/what code should be added that can be able to restrict the form submission.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Cancel href via an onclick

    This is very interesting case because users are always asking about the solution for loading the generated form. But if you need to as you stated in your post then you can do it as. Return true from the onclick to submit the form, return false otherwise:

    Code:
    <a onclick="return myfunction();" href="javascript:generatedfunction();">
    
    
    function myfuncion()
    {
       if ( some condition )
           return true;
       else
          return false;
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    63

    Cancel href via an onclick

    That's right Zecho , I always seen that users need to know about the solution for loading issues but I need to ask just opposite because I am practicing on this..

    By the way, I am glad to know that you all viewed my problems and considered the effective solution, But the solution that you have given to me. According to me, I have tried this already but after your suggestion . I will try it again ...

    Thanks for all this !!

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Cancel href via an onclick

    This is very simple task and you can do to change some lines of code in your function and you need to adjust the false and true according to the need of execution. You need to use javascript function and use return false

    Code:
    <script language "JavaScript" >
    
    function myfunc()
        {
    
          return false;
    }
    
    </script>

  5. #5
    Join Date
    Mar 2010
    Posts
    63

    Cancel href via an onclick

    Hello dear all,

    Thanks for your support and now I have tried to do the same thing again. I put just "return false;" no if clauses or anything - to guarantee it was returning false.

    So my created and coded function looks like this :
    -------------------------------------
    function myfunction()
    {
    alert("here");
    return false;
    }
    -----------------------------------
    The alert indicates me the function was firing. But it still fired the created function next.

  6. #6
    Join Date
    Apr 2008
    Posts
    3,522

    Re: Cancel href via an onclick

    Now, you got it properly that you can use the return to manage the loading of form. One thing more, don't forget to add the proper adjustment of values at proper place and you need to add return with the onclick event and that would be as follows -

    Code:
    <a onclick="return myfunction();" href="javascript:generatedfunction();">

Similar Threads

  1. IE7 href + onclick - both happen
    By Ucchal in forum Software Development
    Replies: 5
    Last Post: 24-05-2010, 03:58 PM
  2. Why does onclick event not cancel href navigation?
    By Cordell in forum Software Development
    Replies: 5
    Last Post: 14-05-2010, 12:03 AM
  3. Dynamic HREF on onClick
    By hounds in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:53 PM
  4. onClick - change href
    By Neutrals in forum Software Development
    Replies: 6
    Last Post: 12-05-2010, 09:25 AM
  5. A Href And OnClick Button
    By Endowed in forum Software Development
    Replies: 5
    Last Post: 11-05-2010, 10:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,750,168.35641 seconds with 16 queries