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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:48:42+00:00 2026-05-24T21:48:42+00:00

I have functions on blur and on focus that change a password text field

  • 0

I have functions on blur and on focus that change a password text field to change from text to password type. What happens is that we deleted and recreate it, but the prototype functions don’t work afterwards. The code is as follows:

function focusPass(inputel,inputval) {
    if(inputel.value == inputval) {
        var newInput = document.createElement('input');
        newInput.setAttribute('type','password');    
        newInput.setAttribute('name',inputel.getAttribute('name'));
        newInput.setAttribute('id',inputel.getAttribute('id'));   
        inputel.parentNode.replaceChild(newInput,inputel);    
        setTimeout(function() { newInput.focus(); }, 10);
    }
}

function blurPass(inputel,inputval) {
    if(inputel.value == '') {
        var newInput = document.createElement('input');
        newInput.setAttribute('type','text');    
        newInput.setAttribute('name',inputel.getAttribute('name'));
        newInput.setAttribute('id',inputel.getAttribute('id')); 
        newInput.value = inputval;
        inputel.parentNode.replaceChild(newInput,inputel); 
    }
}

if ($('j_password') != undefined) {
    blurPass($('j_password'),'password');
    $('j_password').observe('blur', function(e) {  
        blurPass(this,'password');
    });
    $('j_password').observe('focus', function(e) {    
        focusPass(this,'password');
    });
}

I tried doing something like:

document.observe('blur', function(e, el) {  
    if (el = e.findElement('#j_password')) {    
        blurPass(this,'password'); 
    }
});

document.observe('focus', function(e, el) {  
    if (el = e.findElement('#j_password')) {    
        focusPass(this,'password');
    }
});

but that doesn’t seem to do anything. Can someone tell me how I would keep this function working? I would prefer not to have to set an attribute for onblur and onfocus, but if it’s not possible, will revert to that.

Thanks.

  • 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-24T21:48:43+00:00Added an answer on May 24, 2026 at 9:48 pm

    What I ended up doing was:

    function focusPass(inputel,inputval) {
        if(inputel.value == inputval) {
            var ie = getIEVersion();
            if (ie > -1 && ie < 9) {
                var newInput = document.createElement('input');
                newInput.setAttribute('type','password');    
                newInput.setAttribute('name',inputel.getAttribute('name'));
                newInput.setAttribute('id',inputel.getAttribute('id'));  
                new Insertion.After(inputel, newInput);
                inputel.remove();
                setTimeout(function() { newInput.focus(); }, 10);
            } else {
                inputel.setAttribute('type','password');
                inputel.value = "";
                    inputel.focus();
            }
        }
    }
    
    function blurPass(inputel,inputval) {
        if(inputel.value == '') {
            var ie = getIEVersion();
            if (ie > -1 && ie < 9) {
                var newInput = document.createElement('input');
                newInput.setAttribute('type','text');    
                newInput.setAttribute('name',inputel.getAttribute('name'));
                newInput.setAttribute('id',inputel.getAttribute('id')); 
                newInput.value = inputval;
                new Insertion.After(inputel, newInput);
                inputel.remove();
            } else {
                inputel.setAttribute('type','text');
                inputel.value = inputval;
            }
        }
    }
    

    It doesn’t fix the IE7 and IE8 issues, but at least it works on all other major browsers as they support changing the input type.

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

Sidebar

Related Questions

I have some code bound to the blur() event in jQuery: $('input[type=text]').blur(function () {
I have two functions that have different enough logic but pretty much the same
My jQuery function looks like that $('input[type=text]').focus(function() { $(label).css(border-bottom-color, red); }); $('input[type=text]').blur(function() { $(label).css(border-bottom-color,
I have functions that contribute to small parts of a figure generation. I'm trying
I have functions in place that will convert the results of sql queries into
I have several functions that I wrote and I use regularly on my servers,
I have two functions to add and remove table rows that contain a form
Note that this relates to focus and blur events on a window, not on
I have a data entry web app where the control that has focus is
I'm building a simple Facebook tab. I have two tabs that change every 3

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.