Form field’s default value using Mootools
Sometimes it’s needed to put default value for input, textarea field’s in form. If field’s focusd, default value need to be vanished and if no value provided by user and field de-focused, default value need to be back again.
Using javascript, we can do this very easily with inline code but that is very messy. Mootools has very effective selectors class to handle that very easily. Just use the following codes, you don’t have to write anything in the field’s.
window.addEvent('domready', function(){
$(document.body).getElements('input[type=text],textarea').addEvents({
'focus' : function(){
if (this.get('value') == this.defaultValue)
{
this.set('value', '');
}
},
'blur' : function(){
if (this.get('value') == '')
{
this.set('value', (this.defaultValue));
}
}
});
});
This is pretty simple!
Macbook Pro 13.3
Nikon D90
Wao, nice post
javed
July 26, 2009 at 10:20 pm