PDA

View Full Version : Empty value of textbox once active



leetee4000
07-31-2008, 11:04 AM
I want to have a value in a textbox so that the user can see what needs to be entered. When the user selects the box to start entering details I want the it to empty. I have seen this used many times but don't know how this is achieved?

Many thanks

rangana
07-31-2008, 11:12 AM
Please do not cross post.

See if this basic example helps:


<script type="text/javascript">
window.onload=function(){
var inp=document.getElementById('inp'), // Set the input element's ID.
text='Search...'; // Default input text's value. This should match on the value of your value attribute.
inp.onfocus = function()
{this.style.color='#222';this.value=(this.value==text)?'':this.value;}
inp.onblur= function()
{
if(this.value=='')
{
this.value=text;
this.style.color='#aaa';
}
else this.value;
}
}
</script>
<input type="text" value="Search..." id="inp" style="color:#aaa;">

leetee4000
07-31-2008, 12:41 PM
That works brilliantly!! Thankyou