Created
April 27, 2013 20:16
-
-
Save stgogm/5474528 to your computer and use it in GitHub Desktop.
This is a simple code for toggling password input fields into text fields and vice versa. You must provide a listener element, like a check box, and the inputs ID you want to toggle as 'passwordInputA, passwordInputB, ...'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function PasswordsVisible(listener, fields) { | |
| this.obscure = true; | |
| this.fields = fields; | |
| this.listener = $('#' + listener); | |
| this.length = 0; | |
| this.init(); | |
| } | |
| PasswordsVisible.prototype = { | |
| init : function() { | |
| var me = this; | |
| me.fields = me.fields.split(', '); | |
| me.length = me.fields.length; | |
| me.listener.on('click', function() { | |
| me.toggle(); | |
| }); | |
| }, | |
| toggle : function() { | |
| var me = this; | |
| var type = ''; | |
| if (me.obscure) { | |
| me.obscure = false; | |
| type = 'text'; | |
| } else { | |
| me.obscure = true; | |
| type = 'password'; | |
| } | |
| for(var i = 0; i < me.length; i++) { | |
| $('input#' + me.fields[i]).attr('type', type); | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment