# Hide Text onClick



## oysterking (Oct 20, 2009)

Hello everyone, the new guy here. Thought I would see if you all could help.
I am trying to add an onClick event to hide the default text value of my text field. Here is my code without an onClick.

<form method='post' action='{SITE_ROOT}index.php' style='margin:0px'>
<input class="ibox_search" type='text' name='search' value='Search All' style='width:300'> <input class="ibox_search_submit" type='submit' value='{WORD_SEARCH}'>
</form>

Any help would be appreciated.

Thanks


----------



## jamiemac2005 (Jul 5, 2007)

Oh right, just to clarify you want it to hide "Search All" when the input box is clicked? If i'm right in assuming that:


```
<input class="ibox_search" type='text' name='search' value='Search All' style='width:300' onfocus="this.value=='Search All'?this.value='':this.value=this.value;" onblur="this.value==''?this.value='Search All':this.value=this.value;">
```
It makes sence to use onfocus rather than onclick because a user can tab to the input box aswell... And the onblur code simply checks to see if the text box is empty and replaces that with "Search All" if it is.

Cheers,
Jamey

p.s. Welcome to tsf =]


----------



## oysterking (Oct 20, 2009)

Yes that was a correct assumption, works perfect. 
Thanks Jamey, your the bomb !!!


----------



## jamiemac2005 (Jul 5, 2007)

That's cool, glad i got it right =]

Cheers,
Jamey


----------

