Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:42:07+00:00 2026-05-16T17:42:07+00:00

I would like to have something like <textarea>Welcome, click here to type.</textarea> Then clear

  • 0

I would like to have something like <textarea>Welcome, click here to type.</textarea>

Then clear when the user clicks on the text area, obviously.

But.

Before anyone mentions that there are duplicates of this question on this site already there are other details that are not mentioned in the answers. For example:

I’ve seen that it’s possible to clear <textarea> without onclick() and only having an <textarea id="someid">. I just don’t know how they did it, I would like to do this. Not only do I like my code clean but I’d like to know how this was possible. (I’m thinking onClick() somehow being inside the <head><script type="text/javascript"></script></head>?)

I also want the <textarea> to not clear once someone has typed something and clicks on the text area again. i.e. When the user clicks the text area again to edit a certain part of the text entered.

I don’t know much Javascript but this is the way I see it working:

  1. If <textarea> matches the value Welcome, click here to type; it should clear the text once the user clicks in the text area.
  2. If <textarea> is empty and is no longer on focus it should return the value “Welcome, click here to type.” again.

This means clicking on the text area again wouldn’t clear the text, which prevents the text from being cleared once the user has already typed something in the box.

Thanks in advance for helping me out! Your knowledge on this matter would be greatly appreciated. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:42:07+00:00Added an answer on May 16, 2026 at 5:42 pm

    In the <head>, you could do the following:

    <script type="text/javascript">
        var textAreaDefaultText = "Welcome, click here to type.";
    
        function textAreaFocus(textarea) {
            if (textarea.value == textAreaDefaultText) {
                textarea.value = "";
            }
        }
    
        function textAreaBlur(textarea) {
            if (textarea.value == "") {
                textarea.value = textAreaDefaultText;
            }
        }
    
        window.onload = function() {
            var textarea = document.getElementById("your_textarea_id");
            textarea.onfocus = function() { textAreaFocus(this); };
            textarea.onblur = function() { textAreaBlur(this); };
        };
    </script>
    

    In this instance, there’s a distinct advantage in using event handler attributes instead (although at the expense of mixing script in with your markup, something that is not generally recommended for various reasons, chief of which is separation of concerns): the code will then work as soon as the textarea is rendered, whereas with the above method, if the user clicks on the textarea before the rest of the document has loaded, the event handler will not have been created and nothing will happen. Therefore if you don’t mind having a little script in your markup, recommend dropping the window.onload part and instead doing:

    <textarea id="your_textarea_id"
        onfocus="textAreaFocus(this)"
        onblur="textAreaBlur(this)">Welcome, click here to type.</textarea>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to do something like this in HTML5 where I have something
I have an NSString like so: @200hello or @0 something What I would like
I have a file template.txt which contains the following: Hello ${something} I would like
I have a form with two selectfields. I would like that when something is
I would just like your feedback on something. Basically I have a value called
I have some MET data I want to validate which would look something like
I'm looking to create something like in this image. Each block would have an
I'm developing an ajax heavy web app, and would like to have textarea 's
I have custom placeholders in a textarea and I would like every browser to
First time here :) I have a textarea and an input and I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.