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

  • Home
  • SEARCH
  • 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 7811181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:04:00+00:00 2026-06-02T04:04:00+00:00

My code doesn’t run and I want the value to be cleared when you

  • 0

My code doesn’t run and I want the value to be cleared when you click on another

what am I doing wrong?

http://jsfiddle.net/AL2vS/

var placeholderText = $('input').val();

$(placeholderText).focus(function() {
    $(this).attr('value', "");
});
$(placeholderText).blur(function() {
    $(this).attr('value', phTextVal);
});​
  • 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-02T04:04:01+00:00Added an answer on June 2, 2026 at 4:04 am

    You’re using ‘placeholderText’ as a selector, which won’t select anything. Use $('input').focus(... and $('input').blur(... instead.

    UPDATE

    If you want to store the existing value, and then replace it, then store it as .data() in the <input> element itself:

    $('input').focus(function() {
        $this = $(this);
        $this.data('oldval',$this.val());
        $this.val('');
    });
    $('input').blur(function() {
        $this = $(this);
        $this.val($this.data('oldval'));
    });​
    

    http://jsfiddle.net/mblase75/AL2vS/12/

    Or possibly:

    $('input').blur(function() {
        $this = $(this);
        if ($this.val().length==0) { // only if the field is blank
            $this.val($this.data('oldval'));
        };
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code doesn't work as intended, what am I doing wrong? $(document).ready(function(){ $(a.hide-para).click(function(){ $('p').hide();
This simple code doesn't work! http://jsfiddle.net/FPcFn/ $(document).keydown(function(e){ switch (e.which){ case 37: alert(37); } });
this code doesn't compile. I'm wondering what I am doing wrong: private static Importable
This code doesn't work, anyone have any recommendations? Perhaps I did something wrong? Anyone
This code doesn't work what's wrong? $(.re).focus(function() { if($(this).attr(type) == text) { $(this).attr(type, password);
My code doesn't insert any records to mysql. What is wrong? I am really
Why the following code doesn't work? I want that input would be disabled for
The following code doesn't appear to run when executed by code: Stored procedure snippet:
Does anyone know why this code doesn't plot the boxes colors correctly. I want
The below code doesn't work. I want when the mouse hovers over a div

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.