• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1264
  • Last Modified:

Text field to Password field using javascript.

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.

~roshan
0
Roshan Davis
Asked:
Roshan Davis
1 Solution
 
SnowFlakeCommented:
strictly speeking you can not chage the type as the type property is "write-once"
 

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/type_7.asp

>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">
<html>
      <body>
            <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>
            
      </body>
</html>

SnowFlake
0
 
Cem TürkSenior Software EngineerCommented:
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.

cem_turk
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now