Add a text to text box, hide when it is clicked, show when clicked out

My Friend Ukesh gave me this code, thanks to him for saving my time.

<input name="q" id="search_text" type="text" value="- Search -" onfocus="clearDefaultText(this)" onblur="clearDefaultText(this)" style="background:none"/>
<script>
function clearDefaultText(field){

if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;

}
</script>

Comments

Unknown said…
common dude, its just a Javascript :)
Yeah it takes 15-20 mins when I do it, but it took seconds to copy :):) Is there any option in the input tag for doing this kinda work??

Popular posts from this blog

Install Cpanm module error : No such file or directory opening compressed index

How to increase Elasticsearch Shard recovery Speed

Getting started with Python Flask application with MVC structure