make text in a webform text box dissapear whe the user clicks in it


In my web app I have text boxes that allow the user to enter the start and end of a range.
The image below shows this.
I have put the words "From" and "To" to make it easier for new users.
I want these words to disappear if the user clicks in one of the text boxes.
How do I achieve this in

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There in no image,,.
If you want to do this on client side you can use javascript and this code:
<asp:TextBox onclick="txtBox1_ClientClicked()" ID="TextBox1" runat="server" OnClick="TextBox1_Click"></asp:TextBox>
<script type="text/javascript">
    function txtBox1_ClientClicked(){
       // do something
        document.getElementById("TextBox1").value = "";

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Misha. I have several textboxes. How would I change that javascript so that it would affect the text box using it? Do I put that code in the <head> section of the markup?
May be I don`t understand you.. This code have affect to your TextBox1. When you click  on this textbox to input text, its value automatically changed on "".
You can put javascript code to other js file and add link to this file in section head like this:
<script type="text/javascript" src="/scripts/YourTextBoxScript.js"></script>

Open in new window

What do you mean?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Ryan ChongSoftware Team LeadCommented:
or HTML placeholder serves your purpose?

HTML <input> placeholder Attribute

you no need to add any javascript to implement this effect.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
So Misha all I mean is that I want to call that JavaScript from any TextBox. I have 14 of them and it will clear that box.
It works well with TextBox1
Can you add event

Open in new window

to each textBox? And handle it in one place (javascript)
But Ryan Chong solution (placeholder)  is better.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for clarifying that the <input> method is the best answer Midsha and thanks very much Ryan for a great answer
kaufmed   (⌐■_■)Shot Through the Heart, and You're to Blame, You Give vars a Bad NameCommented:
Always keep in mind the availability of these kind of things for cross-browser, if you are in an environment that supports multiple browsers.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Kaufm3d. Is the <input> method better on most browsers?
kaufmed   (⌐■_■)Shot Through the Heart, and You're to Blame, You Give vars a Bad NameCommented:
It's certainly available on most browsers; but as you can see in that link I posted, some browsers still require vendor-specific tags (e.g. :-ms-input-placeholder for IE 11) in order to get placeholder to work correctly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.