473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 1970
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*******@community.nospam> wrote in message
news:A7**********************************@microsof t.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>ClientTextBox</title>
<script language="javascript">
function txt_onblur(txt)
{
var len = txt.value.length;

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_onblur(this);" onfocus="txt_onfocus(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.com>
| References: <A7**********************************@microsoft.co m>
| 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 212.143.94.3
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TFEED02.phx.gbl!tornado.fa
stwebnet.it!tiscali!newsfeed1.ip.tiscali.net!borde r2.nntp.ams.giganews.com!n
ntp.giganews.com!news-out.tin.it!feeder.news.tin.it!207.46.248.18.MISMAT CH!T
K2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371084
| X-Tomcat-NG: microsoft.public.dotnet.framework.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*******@community.nospam> wrote in message
| news:A7**********************************@microsof t.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**********************************@microsoft.co m>
<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.public.dotnet.framework.aspnet
| Message-ID: <Vc**************@TK2MSFTNGXA02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 77
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371305
| NNTP-Posting-Host: tomcatimport2.phx.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>ClientTextBox</title>
| <script language="javascript">
| function txt_onblur(txt)
| {
| var len = txt.value.length;
|
| 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_onblur(this);" onfocus="txt_onfocus(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.com>
| | References: <A7**********************************@microsoft.co m>
| | 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.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: 212.143.94.3
| | Path:
|
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TFEED02.phx.gbl!tornado.fa
|
stwebnet.it!tiscali!newsfeed1.ip.tiscali.net!borde r2.nntp.ams.giganews.com!n
|
ntp.giganews.com!news-out.tin.it!feeder.news.tin.it!207.46.248.18.MISMAT CH!T
| K2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:371084
| | X-Tomcat-NG: microsoft.public.dotnet.framework.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*******@community.nospam> wrote in message
| | news:A7**********************************@microsof t.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
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...
5
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...
2
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...
3
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...
5
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...
1
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..."...
2
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...
4
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...
8
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 ?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.