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 4114642
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:28:53+00:00 2026-05-20T22:28:53+00:00

I have some JQuery that isn’t working and I need a little help. I

  • 0

I have some JQuery that isn’t working and I need a little help. I a few forms on my website, and they all have a textarea with the class “.form-textarea”. What I’m trying to do is use JQuery to get the default value of the textarea, clear the value on focus and reinstate the original value if the the textarea is empty. I realise that an ID would probably be better but I need a generic function to affect all of the textareas with this particular class.

$(document).ready(function()
{
var def = $(".form-textarea")
$(".form-textarea").focus(function(srcc)
{
  if ($(this).val() == def)
    {
      $(this).removeClass("defaultTextActive");
      $(this).val("");
    }
});

$(".form-textarea").blur(function()
{
  if ($(this).val() == "")
    {
      $(this).addClass("defaultTextActive");
      $(this).val(def);
    }
});

$(".defaultText").blur();        
});
  • 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-20T22:28:53+00:00Added an answer on May 20, 2026 at 10:28 pm

    This is an old method I used for the exact same purpose. I believe this is what you’re looking for (uses Textareas) : Live demo

    This uses the jQuery data API. I’ve also added an extra class so you can markup your text nicely (disabled_text). This is a general purpose method so all you need to do is add the suggest class to your textarea/input and the script will do the rest

    <textarea class='suggest'>Some default value</textarea>
    <textarea class='suggest'>Some default value2</textarea>
    <textarea class='suggest'>Some default value3</textarea>
    <input type='text' value ='me too' class='suggest'>
    
    $('.suggest').each(function() {
            $this = $(this);
        if ($this.val() != '') {
            return;
        }
        $this.data('defaultval', $this.val());
    
        $this.addClass('disabled_text').focus(function() {
    
            if ($this.val() == $this.data('defaultval')) {
                $this.val('');
    
            }
            $this.removeClass('disabled_text');
        }).blur(function() {
            var oldVal = ($this.data('defaultval')) ? $this.data('defaultval') : '';
            if ($this.val() == '' && oldVal != '') {
                $this.addClass('disabled_text').val(oldVal);
            }
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with jQuery for the first time and need some help. I have
I have some jQuery/JavaScript code that I want to run only when there is
I have some HTML and jQuery that slides a div up and down to
I have some jQuery code. I have called an Ajax function file, file.php, that
I have some javascript that I'm trying to retool using jQuery to learn the
I have some ASP.NET web services which all share a common helper class they
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I have some jQuery code that highlights which radio button is checked by turning
I have some jQuery code that, without it in the document it passes validation
I have an ancient webpage that I need to instill some databasing capabalities into

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.