Text field to Password field using javascript.

Posted on 2005-05-15
Last Modified: 2010-05-18
Hi Experts,

I have a text field in HTML page.  Using Javascript I just want to change the text to password field and password to text field.

I am developing a software that supports this funtionality in Windows Program using some APIs. I just want to support all those in the HTML also.

PS: I can't create different instance of text field for the password... i have to set it the same field...

Please suggest.

Question by:Roshan Davis
    LVL 15

    Accepted Solution

    strictly speeking you can not chage the type as the type property is "write-once"

    >As of Microsoft Internet Explorer 5, the type property is read/write-once, but only when an input element is created with the createElement method and before it is added to the document.

    however you can overwrite the control with a new instance using outterHTML
    the same method I use here to reconstruct its value can also be used to reconstruct other attributes.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                <INPUT id="Field1" type="password" name="Field1"><br>
                <A href="#" onclick="var v=document.all.Field1.value;document.all.Field1.outerHTML='<INPUT id=Field1 type=text name=Field1>';document.all.Field1.value=v;return false;">Change To Text</span><br>
                <A href="#" onclick="var v=document.all.Field1.value;document.all.Field1.outerHTML='<INPUT id=Field1 type=password name=Field1>';document.all.Field1.value=v;return false;">Change To Password</span><br>

    LVL 17

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

    I will leave the following recommendation for this question in the Cleanup topic area:
        Accept: SnowFlake

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now