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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:17:22+00:00 2026-06-04T02:17:22+00:00

So long story short, aside from being a noob, im not sure why this

  • 0

So long story short, aside from being a noob, im not sure why this is not working.
overall i have different functions to check different things.

for the sake of this example, i have a form (one field to test) with a default value of say.. “enter name here”. so the html below

<input type="text" value="enter name here" id="fieldOne"/>

js below.

// sample vars

var fieldOne = $('#fieldOne');

//this function below will fire on blur.

function checkVal(){
    if($(this).val()== $(this).attr('defaultValue')){
        $(this).css("background-color","red");
        $(this).css("color","white");   
    } else if($(this).val()==""){
        $(this).css("background-color","red");
        $(this).css("color","white");   
        $(this).val("oopsiiee, you forgot this one");

    } else {
        $(this).css("background-color","green");
        $(this).css("color","white");   
    }

}

then on the form field, on blur i do this

fieldOne.blur(checkVal); etc…

this above works,

Now since it has a default value, so i want it so that when user clicks on said field, that that def value disappears.

so i do something like this:

function clearField(){
  $(this).val("");
}

this works

fieldOne.click(clearField); etc…

problem now is that with this, even when the data has been changed from def to whatever, the mssg that was entered disppears again SOOooo, i want to edit this simple function so that, if the mssg is default, clear it. If the mssg is not default then that means its been changed so leave it.
so to this i write this which breaks the whole thing.

function clearField(){
    if($(this).val() == $(this).attr('defaultValue')){
        $(this).val() == "";
    }
}

Not sure whats going on.

ive also tried

function clearField(){
    if($(this).val() == $(this).attr('defaultValue')){
        $(this).attr('defaultValue') == "";
    }
}

Any tips, ideas, corrections etc i humbly accept/appreciate

Thanks in advanced.

  • 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-04T02:17:25+00:00Added an answer on June 4, 2026 at 2:17 am

    Is something like this what you’re looking to accomplish?

    $inputs = $('input[type=text], input[type=password]');
    
    $inputs.focus(function() {
        if(this.value==this.defaultValue)
        {
            this.value='';
        }
    }).blur(function() {
        if($.trim(this.value)=='')
        {
            this.value=this.defaultValue;
        }    
    });
    

    Fiddle of this example: http://jsfiddle.net/yajxr/2/

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

Sidebar

Related Questions

Long story short Say I have the following code: // a class like this
Long story short: I have some controller logic that requests a value from the
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, a piece of code that I'm working with at work has
Long story short, I have an array of integers that represents the .text section
Long story short, I have a situation where egit allows unchanged files to be
Long story short: var o="before"; x = function() //this needs to be an anonymous
Long story short I'm reasonably new to T-SQL, and I'm working on querying some
Long story short, I'm trying to parse an input string into 'tokens'..... I have
Long story short, I have #include <vector> template <class T> class wrapped_vector { private:

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.