Created
March 14, 2012 11:03
-
-
Save snirgel/2035791 to your computer and use it in GitHub Desktop.
Mirrors the input of an textfield, identified by id
This file contains 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
1. Include the code between your head tags after your jquery-include | |
2. Give your input field u want to mirror an id | |
example: <input type="text" id="registration-firstname" class="mirror-value" /> | |
3. Give the element in that you want to mirror an class name composed of the input-mirror-field and the appendix -mirror | |
example: <span class="registration-firstname-mirror"></span> | |
4. Initialize the plugin: | |
example: jQuery('.mirror-value').mirrorValue(); |
This file contains 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
/** | |
* @author Karina Mies | |
* @description Mirrors the input of an textfield, identified by id | |
*/ | |
jQuery.fn.mirrorValue = function(){ | |
return this.each(function(){ | |
var lCurrentText, lId, lMirrorClass; | |
jQuery(this).keyup(function(e) { | |
lId = '#'+jQuery(this).attr('id'); | |
lMirrorClass = '.'+jQuery(this).attr('id')+'-mirror'; | |
lCurrentText = jQuery(lId).val(); | |
jQuery(lMirrorClass).text(lCurrentText); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment