Link to home
Start Free TrialLog in
Avatar of jumpstart0321
jumpstart0321

asked on

Javascript "type your search here"

When a textbox is clicked, I need the text that says "Enter your search term here" to dissappear. What's the javascript for this? Thanks, Chris.
Avatar of Pratima
Pratima
Flag of India image

<asp:TextBox ID="TextBox1" runat="server" Text="Serch Here" onclick="this.value=''"></asp:TextBox>
<input type="text" value="serch here" onclick="this.value=''" />  
<input type="text" onBlur="if (this.value == '') this.value = 'Enter search keywords here';" onFocus="if (this.value == 'Enter search keywords here') this.value = '';" value="Enter search keywords here" style="height: 17px; width: 200px; font-size: 14px; " maxlength="100" size="6" name="keyword"/>
Avatar of jumpstart0321
jumpstart0321

ASKER

Thanks pratima :)  this one worked:
<asp:TextBox ID="TextBox1" runat="server" Text="Serch Here" onclick="this.value=''"></asp:TextBox>
One last question though: what about when a user starts typing something? I need the text to dissappear. The focus is automatically set to the "txtSearch" textbox on load. Thanks, Chris. (I'm using asp.net 2.0 also.
try this

<input type="text" name="txt" id="txt" onclick="doThis ();"

<script type="text/javascript">
function doThis () {
var x = document.getElementById('txt');
x.value="";

}
</script>
you can set foucus at codebehind using on pageload

 TextBox1.Focus();
Right, I already have the focus set. The problem is, when the page loads and it sets the text to "Enter your search here". If people start typing before clicking on the box, it will start the text at the beginning of "Enter your search here". For example, if they type in "frog", it will type frogEnter your search here
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. You're a life saver :)