473,836 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox that clears on first click

Hi

I want to have a textbox on my webpage that shows 'Type here' in gray. When
you click on the textbox, that text disappears and you can type your search,
rather than having to select it and press delete.

Be super-cool if it could also change the textcolor as well.

Any ideas on how to do this? I dont mind using another control, as long as
its free (its for a charity intranet).

Cheers

Dan
Jan 16 '06 #1
3 1984
Dan,

You need to handle client-site keyboard events in javascript. You will have
to work out a bit of logic for detecting very first key pressing.

Eliyahu

"musosdev" <mu*******@comm unity.nospam> wrote in message
news:A7******** *************** ***********@mic rosoft.com...
Hi

I want to have a textbox on my webpage that shows 'Type here' in gray.
When
you click on the textbox, that text disappears and you can type your
search,
rather than having to select it and press delete.

Be super-cool if it could also change the textcolor as well.

Any ideas on how to do this? I dont mind using another control, as long as
its free (its for a charity intranet).

Cheers

Dan

Jan 16 '06 #2
Hi Dan,

As Eliyahu has mentioned, we can just use some clientside scripts to do
such work. We can put some initial text in the textbox and then use the
"onfocus" dhtml event to detect the user's begin inputing , and use
"onblur" event to detect user's move out ....
Here are some simple code snippet which simulate such a TextBox:

<HTML>
<HEAD>
<title>ClientTe xtBox</title>
<script language="javas cript">
function txt_onblur(txt)
{
var len = txt.value.lengt h;

if(len <= 0)
{
txt.value = "Search.... ";
}
}

function txt_onfocus(txt )
{
var val = txt.value;

if(val == "Search.... ")
{
txt.value = "";
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT type="text" id="txtClient" name="txtClient "
onblur="txt_onb lur(this);" onfocus="txt_on focus(this);" value="Search.. .."
/>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Eliyahu Goldin" <re************ *@monarchmed.co m>
| References: <A7************ *************** *******@microso ft.com>
| Subject: Re: Textbox that clears on first click
| Date: Mon, 16 Jan 2006 12:38:22 +0200
| Lines: 29
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| Message-ID: <uY************ **@TK2MSFTNGP15 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 212.143.94.3
| Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTFEED02.ph x.gbl!tornado.f a
stwebnet.it!tis cali!newsfeed1. ip.tiscali.net! border2.nntp.am s.giganews.com! n
ntp.giganews.co m!news-out.tin.it!feed er.news.tin.it! 207.46.248.18.M ISMATCH!T
K2MSFTNGP08.phx .gbl!TK2MSFTNGP 15.phx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3710 84
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Dan,
|
| You need to handle client-site keyboard events in javascript. You will
have
| to work out a bit of logic for detecting very first key pressing.
|
| Eliyahu
|
| "musosdev" <mu*******@comm unity.nospam> wrote in message
| news:A7******** *************** ***********@mic rosoft.com...
| > Hi
| >
| > I want to have a textbox on my webpage that shows 'Type here' in gray.
| > When
| > you click on the textbox, that text disappears and you can type your
| > search,
| > rather than having to select it and press delete.
| >
| > Be super-cool if it could also change the textcolor as well.
| >
| > Any ideas on how to do this? I dont mind using another control, as long
as
| > its free (its for a charity intranet).
| >
| > Cheers
| >
| >
| >
| > Dan
|
|
|

Jan 17 '06 #3
Hi Dan,

Does that helps some? If still anything else we can help, please feel free
to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 64558820
| References: <A7************ *************** *******@microso ft.com>
<uY************ **@TK2MSFTNGP15 .phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 17 Jan 2006 03:23:10 GMT
| Subject: Re: Textbox that clears on first click
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <Vc************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 77
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3713 05
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
| Hi Dan,
|
| As Eliyahu has mentioned, we can just use some clientside scripts to do
| such work. We can put some initial text in the textbox and then use the
| "onfocus" dhtml event to detect the user's begin inputing , and use
| "onblur" event to detect user's move out ....
| Here are some simple code snippet which simulate such a TextBox:
|
| <HTML>
| <HEAD>
| <title>ClientTe xtBox</title>
| <script language="javas cript">
| function txt_onblur(txt)
| {
| var len = txt.value.lengt h;
|
| if(len <= 0)
| {
| txt.value = "Search.... ";
| }
| }
|
| function txt_onfocus(txt )
| {
| var val = txt.value;
|
| if(val == "Search.... ")
| {
| txt.value = "";
| }
| }
| </script>
| </HEAD>
| <body>
| <form id="Form1" method="post" runat="server">
| <INPUT type="text" id="txtClient" name="txtClient "
| onblur="txt_onb lur(this);" onfocus="txt_on focus(this);"
value="Search.. .."
| />
| <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
| </form>
| </body>
| </HTML>
|
|
| Hope helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
| --------------------
| | From: "Eliyahu Goldin" <re************ *@monarchmed.co m>
| | References: <A7************ *************** *******@microso ft.com>
| | Subject: Re: Textbox that clears on first click
| | Date: Mon, 16 Jan 2006 12:38:22 +0200
| | Lines: 29
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | X-RFC2646: Format=Flowed; Original
| | Message-ID: <uY************ **@TK2MSFTNGP15 .phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: 212.143.94.3
| | Path:
|
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTFEED02.ph x.gbl!tornado.f a
|
stwebnet.it!tis cali!newsfeed1. ip.tiscali.net! border2.nntp.am s.giganews.com! n
|
ntp.giganews.co m!news-out.tin.it!feed er.news.tin.it! 207.46.248.18.M ISMATCH!T
| K2MSFTNGP08.phx .gbl!TK2MSFTNGP 15.phx.gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3710 84
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Dan,
| |
| | You need to handle client-site keyboard events in javascript. You will
| have
| | to work out a bit of logic for detecting very first key pressing.
| |
| | Eliyahu
| |
| | "musosdev" <mu*******@comm unity.nospam> wrote in message
| | news:A7******** *************** ***********@mic rosoft.com...
| | > Hi
| | >
| | > I want to have a textbox on my webpage that shows 'Type here' in
gray.
| | > When
| | > you click on the textbox, that text disappears and you can type your
| | > search,
| | > rather than having to select it and press delete.
| | >
| | > Be super-cool if it could also change the textcolor as well.
| | >
| | > Any ideas on how to do this? I dont mind using another control, as
long
| as
| | > its free (its for a charity intranet).
| | >
| | > Cheers
| | >
| | >
| | >
| | > Dan
| |
| |
| |
|
|

Jan 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15735
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New Record button is clicked. The code checks the table for the highest value and then assigns 1 and inserts the value. I have a second text box which needs the same type of custom auto-number which has to be generated from a second command button. ...
5
2511
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are lost, and it reloads what was previously there. Any ideas? try {
2
2977
by: Tim Zych | last post by:
I am trying to follow the instructions from http://authors.aspalliance.com/das/tutorial/fileupload.aspx to upload a file. The webform contains 2 buttons and a textbox. Browse for a file, click the Upload button and it's supposed to save it somewhere. Problem is, when browse for a file and click the Upload button, the textbox get cleared out and the page refreshes. No save action occurs.
3
6777
by: Henry Jones | last post by:
VS 2005 On a form I have a tabcontrol with 5 tabs. Each tab has three textboxes on it. When I click on each tab, I would like to have the focus set to the first textbox. On the tabenter event for each tab, I put a textbox1.focus but the textbox doesn't contain the cursor. How can I do this?
5
1709
by: iDaz | last post by:
hello! i have a textbox, and 2 buttons. this is what i would like: when i click button 1, "1" is added to the textbox. when i click button 2, "2" is added to the textbox. i have tried to do this myself, but when ever i click one of the buttons, it clears the digit that is already in the textbox, and then adds a new digit. i want it to keep adding digit after digit. eg. if i press button 1 three time, then button 2 twice, the textbox shows...
1
4493
by: Radu | last post by:
Hi. I have... well.... not very many computer-literate users to my web- site. For the textbox which expects an email address, for instance, I had to enter a default text like "Email..." because if not, they phoned me asking questions like "What does the message 'Your email address is required' ?" :-)))
2
1662
by: NerdyGirL | last post by:
Hello, I've read thru numerous post/archives trying to decipher the cause of my problem to no avail. I'm just basically trying to conduct a search by using a form in order to locate data that may or may not be in one field of an associated table/query. Here's my 3-step process. 1) I click on the name of my Main form (that I've already created along with a subform and query and an click-on command button) and it prompts me with an "Enter...
4
18377
by: billa856 | last post by:
Hi, My Project is in MS Access 2002. In that I have one form which I am using for data entry. Now in that I have some TextBoxes like PalletNo,TotalPallets,ItemNo,LONo,PONo,BatchNo,LotNo,Cartons,PcsPerCarton etc. Now when person scan a barcode from paper it will automatically enter Number(Like 24914) in first PalletNo TextBox. In the AfterUpdate event of PalletNo TextBox I put some code so it will search the values of...
8
4904
by: fniles | last post by:
I am using VB.NET 2008. I would like to search a textbox (find next and find previous), and when it finds the text, move my cursor in the textbox to where the found text is. How can I do that ? Thank you
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10819
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3100
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.