Solved

textbox or input control

Posted on 2010-08-17
4
385 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:TrialUser
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 33457100
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.
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 33457101

private void tbMyTextBox_Click(object sender, EventArgs e)  

{  

  If(tbMyTextBox.Text == "[enter your search here.]") 

  { 

    tbMyTextBox.Text = string.empty; 

  } 

} 

Open in new window

0
 
LVL 5

Expert Comment

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

Open in new window

0
 
LVL 23

Assisted Solution

by:Kamaraj Subramanian
Kamaraj Subramanian earned 250 total points
ID: 33457122
if you need it in javascript, then check the below code
<html>

<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 = "";

} 

-->

</script>





<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>

</form>





</body>

</html> 

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now