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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:52:33+00:00 2026-05-30T06:52:33+00:00

I am trying to get this simple script to work. Basically, when a user

  • 0

I am trying to get this simple script to work. Basically, when a user clicks on the Show link, it will display the password in the password text box and hide it when it is clicked again. I have searched for solutions but couldn’t find anything for what I need. Here is the code:

JavaScript

    function toggle_password(target){
    var tag = getElementById(target);
    var tag2 = getElementById("showhide");
    if (tag2.innerHTML == 'Show'){
        tag.setAttribute('type', 'text');   
        tag2.innerHTML = 'Hide';
    }
    else{
        tag.setAttribute('type', 'password');   
        tag2.innerHTML = 'Show';
    }

    }

HTML

<label for="pwd0">Password:</label>
<input type="password" value="####" name="password" id="pwd0" />
<a href="#" onclick="toggle_password('pwd0');" id="showhide">Show</a>

When I click the link, nothing happens. I have tested this without using the if statement too and still did nothing.

  • 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-30T06:52:34+00:00Added an answer on May 30, 2026 at 6:52 am

    you weren’t using document on for getElementById

    function toggle_password(target){
        var d = document;
        var tag = d.getElementById(target);
        var tag2 = d.getElementById("showhide");
    
        if (tag2.innerHTML == 'Show'){
            tag.setAttribute('type', 'text');   
            tag2.innerHTML = 'Hide';
    
        } else {
            tag.setAttribute('type', 'password');   
            tag2.innerHTML = 'Show';
        }
    }
    

    your id names are illegal and difficult to work with: pwd'.$x.' you can’t have some of those chars.

    The HTML 4.01 spec states that ID tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).

    also, this method will not work in all browsers, in IE < 9 for instance you can only change .type before the element is attached to the document

    try swapping them:

    function swapInput(tag, type) {
      var el = document.createElement('input');
      el.id = tag.id;
      el.type = type;
      el.name = tag.name;
      el.value = tag.value; 
      tag.parentNode.insertBefore(el, tag);
      tag.parentNode.removeChild(tag);
    }
    
    function toggle_password(target){
        var d = document;
        var tag = d.getElementById(target);
        var tag2 = d.getElementById("showhide");
    
        if (tag2.innerHTML == 'Show'){
    
            swapInput(tag, 'text');
            tag2.innerHTML = 'Hide';
    
        } else {
            swapInput(tag, 'password');   
            tag2.innerHTML = 'Show';
        }
    }
    

    hope this helps -ck

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

Sidebar

Related Questions

I'm trying to get this simple PowerShell script working, but I think something is
I'm trying to get this simple program to work on windows, but it crashes:
I've been trying to get this arrow toggle script work on my page. I
Trying to get a simple string replace to work using a Groovy script. Tried
I'm trying to get a very simple Javascript function to work that will change
I am trying to get this simple php mail script to send mail to
I have been trying everything I can to get this script to work and
I'm trying to get the hang of jQuery and I had this simple bit
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I've been trying to get this code to work for hours! All I need

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.