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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:32:38+00:00 2026-05-11T19:32:38+00:00

well my problem is that, i have a form, which i want to validate

  • 0

well my problem is that, i have a form, which i want to validate the fields using jquery, if the data is correct i let the submit continue, if no i disable the default behavior by returning false(saw that in a tutorial, here).
so i used as i said the jquery syntax, when the document is ready, i registered for the click event of the button, the problme is that code never gets executed. i used firebug but no clue. nothing happens, so here is my code:

$('#submitBtn').click(function()
{
    var password1 = $('#form_password').val();
    var password2 = $('#form_password2').val();
    if( password1 != password2)
    {
        alert("the two passwords are not equal.");
    }
    return false; //to disable the default behavior of the submit btn
});
  • 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-05-11T19:32:39+00:00Added an answer on May 11, 2026 at 7:32 pm

    The proper way of checking a form submission is to check the form’s submit event, not the button’s click event. Change that around and what you have should work, although as it is right now it is always doing return false; so the form would never be sent. This should do it:

    $('#myform').submit(function() {
            var motPasse1 = $('#form_motPasse').val();
            var motPasse2 = $('#form_motPasse2').val();
            if(motPasse1 != motPasse2){
                alert("Les deux mot de passe ne sont pas identiques");
                return false; // cancel form submission if passwords don't match
            }
            return true; // return true if no errors
    });
    

    Finally, I hope you are not keeping the alert there for production purposes. 🙂 There are much, much better ways to display user notifications than an alert. Check out this question for some suggestions, although something as simply as having an error <div> and fading it in is nicer than the ugly default browser alert box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem that the standard library doesn't solve well, and I'm
I have a small problem with jQuery $.ajax() function. I have a form where
I have a form which has about 40 fields.What are the effective patterns to
I have a form containing a list of input fields that the user populates
Well here's my problem I have three tables; regions, countries, states. Countries can be
well i have most probably an extremly stupid problem but could not figure it
Well, I have a really small problem. How can I access an ASP.NET Drop
I have a problem with debugging sessions. My program executes very well in a
the procedure: i have a script which uploads images (via hmtl-form and php) for
I've got a page where I have a ModalPopUpExtender which I want to show

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.