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
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
Please do not cross post.
See if this basic example helps:
Code:<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;">
Last edited by jscheuer1; 07-31-2008 at 05:34 PM. Reason: only one post required after merge of thread
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
That works brilliantly!! Thankyou
Bookmarks