This is simple but sometime its kill our valuable time.
for text field sometime we need to use label as text value, so when mouse click on it the text value should hide, if user doesn’t give any value and point the mouse another field its display value.

<input type="text" 
          onfocus="javascript:this.value==this.defaultValue ? this.value = '' : ''"  
          onblur="javascript:this.value == '' ? this.value = this.defaultValue : '' " 
          value="First Name"  
/>

or
HTML:

<input type='text' value='First Name' onfocus='javascript:check_text_onfous(this)' onblur='javascript:check_text_onblur(this)' />

Javascript:

function check_text_onfocus(obj)
{
    if(obj.value == obj.defaultValue) 
        obj.value = '';
}
function check_text_onblur(obj)
{
    if(obj.value=='')
        obj.value = obj.defaultValue;
}

its works with me on IE,FF,Chrome 🙂

Advertisements