How to show/hide input value on focus?

Michal Kopanski picture Michal Kopanski · Jul 3, 2009 · Viewed 68.2k times · Source

I see this all over the web, but was wondering if anyone has the JavaScript code for the EASIEST way to show input value on blur, but hide in on focus.

Answer

JLGarcia picture JLGarcia · Mar 23, 2011

This always worked for me:

<input 
    type="text" 
    value="Name:"
    name="visitors_name" 
    onblur="if(value=='') value = 'Name:'" 
    onfocus="if(value=='Name:') value = ''"
 />