ruby on rails - JavaScript Password Match only matching on blank -
the following code showing "passwords not match" except blank password confirmation field, no matter password field contains. i'm not sure i'm going wrong here.
view (rails form_for):
<%= form_for @user, :url => user_registration_path |f| %> <%= f.password_field :password, :class=>"span-live", :maxlength=>"50", :placeholder=>"create password*" %> <%= f.password_field :password_confirmation, :class=>"span-live", :maxlength=>"50", :placeholder=>"confirm password*" %><br> <div id="validate-password-status"></div></div>
javascript (custom.js):
$(document).ready(function() { $("#user_password_confirmation").keyup(validatepassword); }); function validatepassword() { var password = $("#user_password").val(); var password_confirmation = $("#user_password_confirmation").val(); if(password == password_confirmation) { $("#validate-password-status").text("passwords match"); } else { $("#validate-password-status").text("passwords not match"); } };
it's hard debug without more knowledge of page. debug this:
- enter password , confirmation. open javascript console , run
validatepassword()
. - if can't see anything, means function got problem.
- if function ran correctly event attachment in
$(document).ready(....)
got problem.
the problem may see page got 2 or more inputs same id, jquery selector got screwed. can try debug , see.
btw, can change $(document).ready(function(){ ... })
$(function(){ ... })
shortcut in jquery.
Comments
Post a Comment