Amit Dhamu

Writes Code

Toggle Password Characters

HTML

<form id="resetPasswordForm" method="post" action="">
    <input type="password" name="pass" class="toggleable"/>
</form>
<a href="javascript:void(0);" id="togglePW" rel="resetPasswordForm">Toggle Password Characters</a>


JavaScript Function

function TogglePassChars(form) {
    $(form + " input").each(function() {
        if($(this).hasClass("toggleable")) {
            $name = $(this).attr("name");
            $class = $(this).attr("class");
            $value = $(this).attr("value");
            $type = $(this).attr("type") == "text" ? "password" : "text";
            $(this).replaceWith("<input type='"+$type+"' name='"+$name+"' value='"+$value+"' class='"+$class+"'/>");
        }
    });
}


jQuery Execution

$("#togglePW").click(function() {
    $form = "#" + $(this).attr("rel");
    TogglePassChars($form);
});


password / toggle / security

← Enable Package Control in Sublime Text Leading Zeroes →