textbox or input control

I have a texbox for "Search". I would like for this to display some default text like "enter your search here". on focus I want to add javascript to automatically clear the text inside the texbox.
for this purpose can I use a asp:textbox if so which event should I call the javascript function. Or should i use <input> and use the onfocus event. any suggestions would be great. thanks.
i am creating the application in asp.net, visual studio.net. thanks
Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You can use a TextBox and still use onfocus. The intellisense will complain because it won't recognise it as an attribute of the control, but it will still get copied to the output. Your other option is to add an onfocus attribute from code-behind, in which case the IDE won't complain but the net result will be the same.
Kamaraj SubramanianApplication Support AnalystCommented:

private void tbMyTextBox_Click(object sender, EventArgs e)  
  If(tbMyTextBox.Text == "[enter your search here.]") 
    tbMyTextBox.Text = string.empty; 

Open in new window

Just us the onfocus javascript tag:
<input type="text" name="search" value="enter your search here" onfocus="javascript:this.value=''">

Open in new window

Kamaraj SubramanianConnect With a Mentor Application Support AnalystCommented:
if you need it in javascript, then check the below code
<title>CodeAve.com (JavaScript: Textbox Change OnClick)</title>
<body bgcolor="#FFFFFF">

<script language=JavaScript>
function clear_textbox()
if (document.text_form.u_input.value == " Enter Your Search Here ")
document.text_form.u_input.value = "";

<form name="text_form" action="http://www.codeave.com/html/post.asp" method=post>
<input name=u_input onFocus=clear_textbox() value=" Enter Your Search Here ">
<input type=submit value=Submit>
<input type=reset>


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.