what is the best method to clear text in a text field, when the user clicks on it...
i.e. if the text search field says "search" and when they click it, it clears the value..
thanks
what is the best method to clear text in a text field, when the user clicks on it...
i.e. if the text search field says "search" and when they click it, it clears the value..
thanks
You could do like:
<input type="text" onfocus="if(this.value == 'search') {this.value=''}" onblur="if(this.value == ''){this.value ='search'}">
In JavaScript you can simple set the value of the contorol to an empty string in the OnFocus event handler.
Normal HTML:
<script type="text/javascript">
function clearThis(target){
target.value= "";
}
</script>
<input type="text" value="Search" onfocus="clearThis(this)" />
jQuery:
<script type="text/javascript">
function clearThis(target){
$(target).val = "";
}
</script>
<input type="text" value="Search" onfocus="clearThis(this)" />
If jquery's an option, I'd consider the watermark plugin
It achieves what you're after, but with a bit more style