Skip to content

Instantly share code, notes, and snippets.

@hanamizuki
Created December 18, 2012 14:22
Show Gist options
  • Save hanamizuki/4328391 to your computer and use it in GitHub Desktop.
Save hanamizuki/4328391 to your computer and use it in GitHub Desktop.
$.fn.bh_label_in_input = function (){
return this.each( function (){
var $form = $( this );
$form.find( '.in-field-label' ).filter( ':visible' ).each( function (){
var $current_input = $( this );
var $label = $current_input.prev().hide().text().replace( '*', '' ).trim();
$current_input.addClass( 'in-field-label-active' );
$current_input.focus( function (){
if( $current_input.val() == $label ){
$current_input.val( '' ).removeClass( 'in-field-label-active' );
}
}).
blur( function() {
var val = $current_input.val();
console.log( val );
if( val == '' ) $current_input.val( $label ).addClass( 'in-field-label-active' );
if( val == $label ) $current_input;
});
$current_input.blur();
});
$form.submit( function ( ){
$form.find( '.in-field-label' ).filter( ':visible' ).each( function (){
var $current_input = $( this );
var $label = $current_input.prev().text().replace( '*', '' ).trim();
if( $current_input.val() == $label ){
$current_input.val( '' ).addClass( 'label-in-input' );
}
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment