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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:20:07+00:00 2026-05-18T23:20:07+00:00

I have input with password type. And I want to do simple thing. If

  • 0

I have input with password type. And I want to do simple thing. If input isn’t in focus, input has default value. I try to do it with jQuery.
My HTML:

<input type="password" name="password" id="password" defvalue="password" class="filling-password">

My Javascript(jQuery):

$('.filling-password').each(function(){
    var b = $(this);
    var id = this.id;
    var val = b.attr("defvalue");
    var textInput = '<input id="'+id+'-text" type="text" value="'+val+'">';
    $(textInput).insertAfter(this);
    b.hide(0);
    $("#"+id+"-text").focus(function(){
        $(this).hide(0);
        b.show(0).focus();
    });
    b.blur(function(){
        if ($(this).val() == "") {
            $(textInput).insertAfter(this);
            b.hide(0);
        }
    });
});

All work nice. But only one time. When I click first time input become empty, when I blur input have default value.
But If I click third time nothing happen. What is wrong? Or maybe there are better ways to do this?

  • 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-18T23:20:07+00:00Added an answer on May 18, 2026 at 11:20 pm

    Here’s one way roughly as you described it, inserted inside $(function() { ... }); of course (live demo):

    $('.filling-password').each(function() {
        var pass = $(this),
            text = $('<input type="text"/>').val(pass.attr('defvalue'));
    
        text.insertBefore(pass).focus(function() {
            text.hide();
            pass.show().focus();
        });
    
        pass.hide().blur(function() {
            if (pass.val() == '') {
                pass.hide();
                text.show();
            }
        });
    });
    

    Possibly better is to overlay a label on top of the text box (live demo):

    $('.filling-password').each(function() {
        var pass = $(this),
            div = pass.wrap('<div/>').parent(),
            label = $('<label/>').attr('for', pass.attr('id')).text(pass.attr('defvalue')).prependTo(div);
    
        div.css({
            display: 'inline',
            position: 'relative'
        });
    
        label.css({
            color: '#666',
            fontSize: '12px',
            position: 'absolute',
            left: '4px',
            bottom: '2px'
        });
    
        pass.focus(function() {
            label.hide();
        }).blur(function() {
            if(pass.val() == '') {
                label.show();
            }
        });
    

    There’s a jQuery plug-in that implements the latter approach more nicely.

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

Sidebar

Related Questions

I have a text input which has a default value password. When the user
I have this: <input type=text value=Enter Password class=password /> ... onclick/onfocus, I'd like to
In this blog, http://www.bswebdev.com/2008/12/javascript-change-input-box-type-to-password/ I have found the following snippets for fixing change input
I am writing because I have a problem with the input type password. The
I have following HTML code. writer input field is text filed. but I want
Say I have a table html like so and jquery. I want to find
I have a program that is going to take a password as input and
I have a login form that has Username and password as inputs from user
I have a simple form for a login, and I want to display the
What I want : To, on focus, change one input box into another by

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.