• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

I do not want page to submit if function is not met

Hi,

Below I have a submit button:

<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler();" /></p>

Open in new window


Now when the user clicks on the submit button, it performs the jquery function below:

   <script type="text/javascript">
    			
function myClickHandler(){
     if(validation()){
                showConfirm();
     }
}

</script>

Open in new window


Now what the function does is that if the validation() function is met, then it will perform the showConfirm() function (this function will display the confirmation box). But what is happening at moment is that if the validation() function is not met, it is still submitting the page.

Now the problem is that I cannot pet
return false;

Open in new window

in the submit button because this will mess up my page numbers. So my question is that is there a way in the jquery function so that if the validation() function is not met, then do not submit the page?
0
carlbrooks1995
Asked:
carlbrooks1995
2 Solutions
 
aprestoCommented:
Can you use this:

function myClickHandler(){
     if(validation()){
                showConfirm();
        return true;
     }
    else
{
    return false;
}
}

and in the button put return myClickHandler();

or something similar
0
 
leakim971PluritechnicianCommented:
Use : return myClickHandler();
<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="return myClickHandler();" /></p>

Open in new window


   <script type="text/javascript">
    			
function myClickHandler(){
     if(validation()){
               //return showConfirm();
               showConfirm();
               return true;
     }
     return false;
}

</script>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now