Return to Snippet

Revision: 28340
at August 6, 2010 04:33 by brandonjp

Updated Code
// 201004291250 - Mootools clear input on focus, return default value if no data entered
// FROM:  Clear text field with mootools on focus. - MooTools Users | Google Groups

	I've got this snippet that will clear the value on focus and if the value of 
	the focus is '' it will put the default value again in the input. You will 
	need the default value to be on an attribute of the input, like alt or 
	anyother (if you don't bother about validation). 
	Fábio Miranda Costa 
	Engenheiro de Computação 



    clearFocusResetBlur: function(attr){ 
        var valueString = this.get(attr); 
            'focus': function(){ 
                if( this.get('value') == valueString ) this.set('value',''); 
            'blur': function(){ 
                if( this.get('value') == "" ) this.set('value',valueString); 

// Usage
// HTML: 
// <input id="input_id" value="some value" alt="default value" /> 

// JS: 
$('.jform form .cleardefault').set('alt','value').clearFocusResetBlur('alt');

Revision: 28339
at July 7, 2010 04:27 by brandonjp

Initial Code

Initial URL

Initial Description

Initial Title
MOOTOOLS JS - Clear input field onClick onFocus on click focus active

Initial Tags
form, javascript, js, textmate, function

Initial Language