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 7866773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:30:13+00:00 2026-06-03T00:30:13+00:00

I wrote a simple script for validating forms in jQuery. These are the submit

  • 0

I wrote a simple script for validating forms in jQuery.
These are the submit buttons:

<button type="submit" id="submitCrear"  name="submitCrear">Confirm</button> ---->Cancel button
<button type="submit" value="cancelar"  name="cancelar" id="btnCancelar">Cancel</button> ---->Confirm button

When the Cancel button is pressed, the form should be sent without making any validation. The opossite should happend with the Confirm button.

But this is what I don’t understand: when I press the Confirm button, the validation process starts normally, but then I press the Cancel button and the form is not send until all validations are complete(isValidForm variables becomes ‘true’).

<script type="text/javascript"> 
    var isValidForm;
    $(document).ready(function() {              
        $('#btnCancelar').click(function () {
            $('form').submit();
        });

        $('#submitCrear').click(function () {
            $('form').submit(function(){
                return validarForm();
            });
        });
    });

    function validarForm(){
        isValidForm = true;
        $("input:text").each(function(i) {
            if(this.value == ''){
                if (!$("#errorMessage"+i).length > 0)
                    addErrorMessage(this, i, '*REQUERIDO');
                isValidForm = false;
            }else{
                removeErrorMessage(this, i);
            }
        });
        $("input:password").each(function(i) {
            if(this.value == ''){
                if (!$("#errorMessage"+(i+999)).length > 0)
                    addErrorMessage(this, (i+999), '*REQUERIDO');
                isValidForm = false;
            }else{
                if(($(this).attr('id') == 'rePassword_r') && ($(this).val() != $("#password_r").val())){
                    if ($("#errorMessage"+(i+999)).length > 0){
                        removeErrorMessage(this, (i+999));
                        addErrorMessage(this, (i+999), 'The password doesn't match.');
                    }
                    isValidForm = false;
                }else{
                    removeErrorMessage(this, (i+999));
                }
            }
        });
        return isValidForm;
    }

    function addErrorMessage(element, indice, mensaje){
       ...

    }

    function removeErrorMessage(element, indice){
        ...
    }
</script>   

What should I do in order to send the form with the Cancel button even when the validation process started?

Thanks in advance!

  • 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-03T00:30:14+00:00Added an answer on June 3, 2026 at 12:30 am

    You have your two buttons and the following jQuery

        $(document).ready(function() {              
        $('#btnCancelar').click(function () {
            $('form').submit();
        });
    
        $('#submitCrear').click(function () {
            $('form').submit(function(){
                return validarForm();
            });
        });
    });
    

    The latter part of the jQuery means that when the form is submitted, it will be validated as you’ve assigned the validation to the form submittance, rather than the button click. Which is why it is now fired on both buttons.

    By design, don’t buttons of type submit, submit the form regardless? So should you not just change your jQuery to be:

     $(document).ready(function() {              
    
        $('#submitCrear').click(function () {
                return validarForm();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple script for validating login form as follows: <script type=text/javascript> function
I wrote a simple script to solve a logic puzzle, the type of puzzle
I'm learning JQuery and I wrote a simple AJAX external script for my homepage
I wrote a simple jQuery script and the .hide() is not properly rendering. You
I wrote a simple script that is intended to do hierarchical clustering on a
A couple of weeks ago, I wrote a simple Ruby script to test a
I want to write a very simple script , which takes a process name
I am trying to write a simple piece of Jquery in which the script
I wrote a simple javascript function for validating to fields in a aspx page
I wrote simple script test echo hello #<-- inside test if I press one

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.