Solved

textbox or input control

Posted on 2010-08-17
4
403 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

831 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