Solved

textbox or input control

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

760 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

17 Experts available now in Live!

Get 1:1 Help Now