Compare fields in jQuery

0

I need to compare the fields as the script below:

    $("#send_request").submit(function(event){
        var password  = '7c4a8d09ca3762af61e59520943dc26494f8941b'; 
        if($('#userpassword').val()!=password){
            alert('senha invalida');
        }
      event.preventDefault();
    });

Only the userpassword password for this field will come unencrypted, so I'll have to encrypt before comparing. But the form passes straight, neither compares and does not give at all. How should I do it?

    
asked by anonymous 21.05.2016 / 00:16

1 answer

0

Without seeing the html code of the form is a bit complicated, but your code js seems to me to be ok, I managed to make it run here without further problems, without considering that it is not encrypting anything yet. My form has done so, look if you agree:

<form id="send_request" action="#" method="POST">
  <input id="userpassword" type="text">
  <button type="submit">Enviar</button>
</form>  
$("#send_request").submit(function(event){  
  var password  = '7c4a8d09ca3762af61e59520943dc26494f8941b'; 
  if($('#userpassword').val()!=password){
    alert('senha invalida');
  }
  event.preventDefault();
});
    
21.05.2016 / 01:28