Tuesday, November 6, 2012

show plain text in a password field and then make it a regular password field on focus

Use html as
<input type="text" value="password" id="password">

And use script 
jQuery( document ).ready( function(){

    jQuery( document ).delegate( "#password", "focusin focusout",
        function(e){
        var elm = jQuery( "#password" )[0];
            if( e.type == "focusin" && elm.type == "text" ) {
            jQuery( elm ).replaceWith( jQuery( "<input>", {id: "password", type:"password", value:"" } ) );
            jQuery( "#password")[0].focus();
            }
            else if( e.type =="focusout" && elm.type == "password" && !elm.value ) {
                jQuery( elm ).replaceWith( jQuery( "<input>", {id: "password", type:"text", value:"password" } ) );
            }
        
        }
    );
});

No comments:

Post a Comment