Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

textbox or input control

Posted on 2010-08-17
4
Medium Priority
?
425 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 1000 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

972 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