Cancelling the hyperlink navigation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maralfarshadi
    New Member
    • Jul 2007
    • 14

    #1

    Cancelling the hyperlink navigation

    Hi

    I have a hyperlink in my form, and I am using:

    Code:
    <a href="javascript:myFunction('myTextBox','myFormName','ServletName')"> Go </a>

    In my Javascript code, if all goes well, the form gets submitted and the page is forwarded to a servlet. If not, it should just alert the user and cancel the navigation.


    Code:
    if ((Fld.value.length==0) || (Fld.value==null) {
            alert("Please Enter the information");
            return false;  
        }
        else {
            
            //Submit form and go to servlet
    
        }

    I have used the same code for a button and it works without problems. But since this is a hyperlink, instead of cancelling the navigation, I just get a Webpage with 'False' wirtten on top.

    Is there a way to implement this with a hyperlink to work as appropriately as a button? I need to use hyperlinks according to design of some forms

    Thank you for your help
    Maral
    Last edited by maralfarshadi; Feb 28 '08, 04:35 PM. Reason: Addition
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Try this..[html]<a href="javascrip t:myFunction('m yTextBox','myFo rmName','Servle tName')" onclick="return validate()"> Go </a>[/html]If validation is done in myfunction(), then try to make a separate validate() function.

    Comment

    • maralfarshadi
      New Member
      • Jul 2007
      • 14

      #3
      Originally posted by hsriat
      Try this..[html]<a href="javascrip t:myFunction('m yTextBox','myFo rmName','Servle tName')" onclick="return validate()"> Go </a>[/html]If validation is done in myfunction(), then try to make a separate validate() function.
      Thank you very much for suggesting that.

      Comment

      Working...