Return to Snippet

Revision: 50139
at October 1, 2012 23:19 by mortu


Updated Code
//search .click events        
        var default_value = new Array();
        $('input[type=text], textarea').each(function(){
                default_value[$(this).attr('name')] = this.value;      
        });
        
        $('input[type=text], textarea').focus(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == default_value[$(this).attr('name')]){
                        this.value = '';
                }	
        }); 
        $('input[type=text], textarea').blur(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == ''){
                        this.value = default_value[$(this).attr('name')];
                }	
        });



// even a better option - this takes the title value

// toggle input text on blur
$('input.toggle-text').focus(function(){
    var input = $(this);
    var defaultText = input.attr('title');
    input.val('');
    input.blur(function() {
        var userInput = $(this).val();
        if (userInput == ''){
            $(this).val(defaultText);
        }
    });
});

Revision: 50138
at August 12, 2011 18:52 by mortu


Updated Code
//search .click events        
        var default_value = new Array();
        $('input[type=text]').each(function(){
                default_value[$(this).attr('name')] = this.value;      
        });
        
        $('input[type=text]').focus(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == default_value[$(this).attr('name')]){
                        this.value = '';
                }	
        }); 
        $('input[type=text]').blur(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == ''){
                        this.value = default_value[$(this).attr('name')];
                }	
        });



// even a better option - this takes the title value

// toggle input text on blur
$('input.toggle-text').focus(function(){
    var input = $(this);
    var defaultText = input.attr('title');
    input.val('');
    input.blur(function() {
        var userInput = $(this).val();
        if (userInput == ''){
            $(this).val(defaultText);
        }
    });
});

Revision: 50137
at August 12, 2011 00:55 by mortu


Initial Code
//search .click events        
        var default_value = new Array();
        $('input[type=text]').each(function(){
                default_value[$(this).attr('name')] = this.value;      
        });
        
        $('input[type=text]').focus(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == default_value[$(this).attr('name')]){
                        this.value = '';
                }	
        }); 
        $('input[type=text]').blur(function(){
                if(typeof(default_value[$(this).attr('name')]) != 'undefined' && this.value == ''){
                        this.value = default_value[$(this).attr('name')];
                }	
        });

Initial URL

                                

Initial Description
input focus&blur actions

Initial Title
input focus&blur actions

Initial Tags
jquery

Initial Language
jQuery