The correct way to check for form submission is to check the submit form event, not the click button. Change this, and what you have should work, although now it always makes return false; , so the form will never be submitted. 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;
Finally, I hope you do not keep an alert there for production purposes. :) There are many, much better ways to display user notifications than a warning. Check this question for some suggestions, although something like just a <div> error and damping in it is better than the ugly default browser warning window.
source share