Skip to content

Instantly share code, notes, and snippets.

@snirgel
Created March 14, 2012 11:03
Show Gist options
  • Save snirgel/2035791 to your computer and use it in GitHub Desktop.
Save snirgel/2035791 to your computer and use it in GitHub Desktop.
Mirrors the input of an textfield, identified by id
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();
/**
* @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