Skip to content

Instantly share code, notes, and snippets.

@philoye
Created September 22, 2010 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philoye/591216 to your computer and use it in GitHub Desktop.
Save philoye/591216 to your computer and use it in GitHub Desktop.
// jQuery Plugin: Don't Confirm Passwords
//
// This marginally useful plugin might be helpful if you don't want to make users type password twice,
// but can't change the backend. The server still gets two password values.
//
// 1. This should unobtrusively hide a confirm password field and update its value based on the password field.
// 2. It assumes HTML of the following sort:
//
// <fieldset>
// <ul id="password-wrapper">
// <li>
// <label for="choose-password">Choose a password</label>
// <input name="password" type="password" id="choose-password">
// </li>
// <li>
// <label for="confirm-password">Confirm your password</label>
// <input name="passwordConf" type="password" id="confirm-password">
// </li>
// </ul>
// </fieldset>
(function( $ ){
$.fn.dontConfirmPasswords = function() {
return this.each(function() {
var $container = $(this),
$pw_container = $(this).children(":first"),
$cpw_container = $(this).children(":last").hide(),
$pw_field = $pw_container.children("input[type=password]:first"),
$conf_pw = $cpw_container.children("input[type=password]:last");
$pw_field.bind("change keyup", function() {
$conf_pw.val( $(this).val() );
});
});
};
})( jQuery );
$(document).ready(function(){
$("#password-wrapper").dontConfirmPasswords();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment