Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:13:45+00:00 2026-06-11T22:13:45+00:00

I have a form that requires some post validation warnings. The concept is simply,

  • 0

I have a form that requires some post validation warnings. The concept is simply, the values are allowed, but out of normal range. The way this is being handled is in the validation submitHandler:

$('form').validate({
    highlight: function (element, errorClass) {$(element).addClass("invalidElem");},
    unhighlight: function (element, errorClass) {$(element).removeClass("invalidElem");},
    errorPlacement: function (error, element) {element.parent().parent().next().children().last().append(error);},
    errorClass: "errorMsg",

    submitHandler: function (form) {

        if (!WeightsRangeValidator("Height", txtHeight, heightWarning)) {
            return false;
        }

        if (!WeightsRangeValidator("Weight", txtWeight, weightWarning)) {
            return false;
        }

        form.submit();
    }        
});

The problem is that there is both a submit and a cancel button on the form. The cancel button does have the class ‘cancel’ so that the validation does not execute. The submitHandler function is being called still, though. I assume there has to be a way to detect which of the submit buttons is being clicked as to bypass the contents of the submitHandler handler.


here is a working jsFiddler: http://jsfiddle.net/scarleton/ZSVFP/

There are three valid states of the form: either check box (but not both) or both text boxes and the drop down. The validation works when you click on OK. The problem comes in on the cancel. If you enter anything into the text box and press cancel, the validation still tries to validate. I tried added the following handler and it allows cancel if the form is valid, but not if letters are entered in the text box.

btnCancel.click(function () {
    txtHeight.rules("remove");
    txtWeight.rules("remove");
    ddlDevice.rules("remove");
    $("#form").submit();
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:13:47+00:00Added an answer on June 11, 2026 at 10:13 pm
    $('.submitBtn').on('click', function(){
        var $frm =  $ ("#form");
        $frm.validate()
        if($frm).valid()){
           submitHandler();
         $frm.submit()
        }
    })
    
    $('.cancel').on('click', function(){
       var $frm =  $ ("#form");
       if($frm.valid()){
        // Do Some action ...;
       }
    })
    

    OR
    You can add click events on buttonsm and each time change param according on what buttons was clikcef, for more details see example
    [DEMO][1]

    See jquery docs http://docs.jquery.com/Plugins/Validation%5B1%5D: http://jsfiddle.net/abaksheyev/jKuVa/1/

    There are more smart way

    submitHandler: function (form) {
          var val = $("input[type=submit][clicked=true]").val() // add this line to handler
      .......
    
    
    //Add this into document.ready 
    $("form input[type=submit]").click(function() {
        $("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
        $(this).attr("clicked", "true");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that requires the user to enter some information. If they
I have a form that has label values that I would like to pass
I have a form that the user submits and returns a result, but it
I have a form that i want an administrator to fill out, then click
I have a project that requires that I run some code when the application
I have a form with multiple fields that I'm validating (some with methods added
I have a form that I currently enumerate with some Javascript functionality and then
I have an issue, where by I am doing a simple form validation, that
I have an admin form that lets users create entities that require an image.
I currently have form that checks if a user has unsubmitted changes when they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.