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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:29:11+00:00 2026-06-15T19:29:11+00:00

I am building a jQuery form validation plugin. The script uses the title attribute

  • 0

I am building a jQuery form validation plugin. The script uses the title attribute to label the input field. This led to swapping out the input password for input text for the field title to be readable.

$(FormID).find('input:password').each(function() {  
    $("<input type='text'>").attr({ name: this.name, value: this.value, title: this.title, id: this.id }).insertBefore(this); 
}).remove();

When I click on the password input box it works as expected. The following code swaps out the text input for a password input, removes the label, applies the appropriate style and focus.

$(":input").focus(function(){//Clears any fields in the form when the user clicks on them       
   if ($(this).hasClass("va") ) {
        $(this).val('');
        $(this).removeClass("va").addClass('focused');
   }
});
$(':input[title]').each(function() {//Add the title attribute to input fields and disappear when focused 

    if($(this).val() === '') {
        $(this).val($(this).attr('title')); 
    }

    $(this).focus(function() {
        if($(this).val() == $(this).attr('title')) {
            $(this).val('').addClass('focused');
        }
        if ($(this).attr('id')=="pass1" || $(this).attr('id')=="pass2") {
            $("<input type='password'>").attr({ name: this.name, title: this.title, id: this.id }).insertAfter(this).prev().remove();
            $("#"+$(this).attr('id')).focus().addClass('focused');
        }
    });

    $(this).blur(function() {
        if($(this).val() === '') {
            $(this).val($(this).attr('title')).removeClass('focused');
        }
        if ($(this).attr('id')=="pass1" || $(this).attr('id')=="pass2") {
            $("<input type='text'>").attr({ name: this.name, value: this.value, title: passtitle, id: this.id }).insertAfter(this).prev().remove();
            $("#"+$(this).attr('id')).blur().removeClass('focused');
        }
    });
});

The blur function won’t fire when the user clicks outside the focused input box. How do I get it to blur like the other form elements?

  • 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-15T19:29:12+00:00Added an answer on June 15, 2026 at 7:29 pm

    Update: After re-reading your question more thoroughly I’m changing my answer.

    You’re basically trying to make the “title” of the input element appear in the box when the input is not focused. This is a common thing to do but your approach is outdated. I suggest using the HTML5 “placeholder” attribute instead. It’s native to any modern browser (I have a solution for older browsers and IE). However, you still won’t be able to show the placeholder text in a password field. Generally this shouldn’t really be required or even done at all in my opinion. Password fields generally have a slightly different appearance than normal text fields so changing the input may cause slight display glitches.

    To use a placeholder simply build your input like this:

    <input name="username" placeholder="Username" type="text" />
    

    The “placeholder” attribute will be used to populate the displayed text in the input but it has no affect on the actual value of the input.

    To fix IE’s lack of support I created the following jquery placeholder plugin on github awhile ago.

    Now, here is a full working example which is cleaner than your original solution. I’ve tested it in FF17 and IE9. Notice the password input actually starts out as a TEXT field so the placeholder will be shown by default. It only changes to a PASSWORD if the user focuses and enters something.

    <!DOCTYPE html>
    <html>
    <head>
        <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
        <script src="jquery.placeholder.js" type="text/javascript"></script>
    </head>
    
    <body>
        <form>
            <input name="username" placeholder="Username" type="text" />
            <input name="password" placeholder="Password" type="text" data-ispw="1" />
        </form>
    </body>
    
    <script type="text/javascript">
    $(function(){
        // make sure to include the jquery.placeholder.js plugin before using this
        $(':text[placeholder]').placeholder();
        $('form').on({
            focus: function(e){
                // swap to password
                $(this).prop('type', 'password');
            },
            blur: function(e){
                var me = $(this);
                if (me.val() == '') {
                    // swap to text; if no value is entered
                    me.prop('type', 'text');
                }
            }
        }, ':input[data-ispw]')
    });
    </script>
    </html>
    

    Let me re-iterate that I don’t like the idea of swapping the password input like this, but hey, to each their own! Good luck!

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

Sidebar

Related Questions

I am building a site which uses jQUery validation plugin and want things validated
I'm building a registration page that uses JQuery's validator plugin to validate the form.
Im building a Jquery form validation plugin. my concern is that my plugin does
I'm building a website that uses jQuery for things like Modals and form validation.
I'm building a price estimator form, which uses jQuery to manipulate select menus. Basically,
I am using the jQuery Validation plugin to validate a signup form for my
I'm building an app in CodeIgniter. I have an invoice form which uses jQuery
I am building a form, where required field validation must have been checked. I
A friend and I are building a jQuery Form Creator/Validator plugin, and we are
I'm building a contact form that uses ajax via jQuery to fetch a CAPTCHA

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.