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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:19:13+00:00 2026-06-09T12:19:13+00:00

I need it to clear the default input value on focus, and bring the

  • 0

I need it to clear the default input value on focus, and bring the value back if the value is empty on blur. Here is my current code:

$(document).ready(function() {
    function toggleText(selector, value) {
        $(selector).focus(function() {
            if ($(this).val == value) {
                $(this).val('');
            }
        });
        $(selector).blur(function() {
            if ($(this).val == '') {
                $(this).val(value);
            }
        });
    }
    toggleText('input[name="first-name"]', 'First name...');
});
  • 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-06-09T12:19:15+00:00Added an answer on June 9, 2026 at 12:19 pm

    It’s $(this).val(), not $(this).val:

    $(document).ready(function() {
        function toggleText(selector, value) {
            $(selector).focus(function() {
                if ($(this).val() == value) {
                    $(this).val('');
                }
            });
            $(selector).blur(function() {
                if ($(this).val() == '') {
                    $(this).val(value);
                }
            });
        }
        toggleText('input[name="first-name"]', 'First name...');
    });
    

    Edit:

    But I think it’s better this way:

    $(document).ready(function() {
        function toggleText(selector) {
            $(selector).focus(function() {
                if ($(this).val() == $(this)[0].defaultValue) {
                    $(this).val('');
                }
            });
            $(selector).blur(function() {
                if ($(this).val() == '') {
                    $(this).val($(this)[0].defaultValue);
                }
            });
        }
        toggleText('input[name="first-name"]');
    });
    

    you can use $(this).defaultValue() if you use this plugin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clear the default values from input fields using js, but all
Is there a way to clear the input values of the default search manager
I need to have my Django application allow me to have a default value
I'm not clear on how to stop a document-based application from displaying an empty
I need to clear the selection from a <select> element. I've already read such
I need to clear/ reset my textbox1 which is set to ReadOnly= true. I
I need to clear the <div> and insert new content I get from the
I need to clear all APC cache entries when I deploy a new version
Hi I need to clear IE8 browser cache before loading my cd-based php application.
I have a chart and I need to clear it in order to populate

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.