Created
February 1, 2010 04:47
-
-
Save navitronic/291462 to your computer and use it in GitHub Desktop.
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
| // Extend jQuery to add a function for implementing "Nice Inputs" | |
| jQuery.fn.makeNiceInput = function(){ | |
| // Setup the selected elements as nice inputs. | |
| jQuery(this).each(function(){ | |
| if(jQuery('label[for='+jQuery(this).attr('id')+']').length > 0){ | |
| var MNval = jQuery('label[for='+jQuery(this).attr('id')+']').hide().text(); | |
| if(jQuery(this).val() == ''){ | |
| jQuery(this).val(MNval); | |
| } | |
| $(this).addClass('isMNice'); | |
| } | |
| }); | |
| jQuery(this).bind('focus', function(){ | |
| if(jQuery(this).hasClass('isMNice') && jQuery(this).val() == jQuery('label[for='+jQuery(this).attr('id')+']').text()){ | |
| jQuery(this).val(''); | |
| } | |
| }); | |
| jQuery(this).bind('blur', function(){ | |
| if(jQuery(this).hasClass('isMNice') && jQuery(this).val() == ''){ | |
| jQuery(this).val(jQuery('label[for='+jQuery(this).attr('id')+']').text()) | |
| } | |
| }); | |
| jQuery('form').bind('submit', function(){ | |
| jQuery(this).find('.isMNice').each(function(){ | |
| if(jQuery(this).val() == jQuery('label[for='+jQuery(this).attr('id')+']').text()){ | |
| jQuery(this).val(''); | |
| } | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment