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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:51:47+00:00 2026-05-25T21:51:47+00:00

i have a input field for entering password in a webpage: <input name=txtPassword type=text

  • 0

i have a input field for entering password in a webpage:

<input name="txtPassword" type="text" class="input2" id="txtPassword" value="Password" onfocus="txtOnFocus2('txtPassword','Password');" onblur="txtOnBlur2('txtPassword','Password');" />

in the initial state the usershould read “password” as the initial value and when he starts typing a password, the field should change to type password. Also when he sets it back to blank or initial value the field should change type to “text” and show password.

I wrote code an got it working on Firefox, Chrome, and safari and its not changing the type to password on IE 8.

this is the js code i made by editing an existing function code:

 function txtOnFocus2(elementId, defaultText)
 { 
    if (document.getElementById(elementId).value == defaultText)
    {
       document.getElementById(elementId).value = "";
  document.getElementById(elementId).type = "password";
    }
 }

 function txtOnBlur2(elementId, defaultText)
 {
    var textValue = document.getElementById(elementId).value;

    if (textValue == defaultText || textValue.length == 0)
    {
      document.getElementById(elementId).type = "text"; 
  document.getElementById(elementId).value = defaultText;
    }
 }

This is working fine in Firefox,chrome and safari but doesn’t change field type on IE 8.

  • 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-25T21:51:47+00:00Added an answer on May 25, 2026 at 9:51 pm

    An alternative solution would be to change your approach altogether. The following technique degrades gracefully, is more accessible, and less JavaScript-dependant:

    HTML

    <div><label for="email">Email</label> <input type="text" name="email" id="email" /></div>
    <div><label for="password">Password</label> <input type="password" name="password" id="password" /></div>
    

    JavaScript

    $('input')
        .focus(function() {
            $(this).css('background-color', 'white');
        })
        .blur(function() {
            if($.trim($(this).val()) == '') {
                $(this).css('background-color', 'transparent').val('');
            }
        });
    

    CSS

    input {
        background-color: transparent;
        padding: 2px;
    }
    
    label {
        color: gray;
        padding: 2px 4px;
        position: absolute;
        z-index: -1;
    }
    

    Live demo: http://jsfiddle.net/rjkf4/

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

Sidebar

Related Questions

I have input field <input type=text name=vehicle_make[] id=make1/> and i have help dropdown that
I have an input field that is by default set to type=text so that
I have an input field whose name is an MD5 string e.g.: <input type=hidden
I have a form with the following dynamically added row: <input type=text name=statuseffective id=statuseffective_0
I have an input field on my page where the user will type in
I have an input field where both regular text and sprintf tags can be
I have an input field which has a placeholder text. I want one word
I have seen extension with flexform where an input field is for entering an
I have an input field for users to input a monetary amount: <input type="number"
I'm building a text input field specialized for entering and editing times. One of

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.