Click here to Skip to main content
11,568,157 members (35,415 online)
Click here to Skip to main content

Tagged as

Changing type of a textbox from text to password using javascript

, 21 Jul 2010 CPOL 11.8K 1
Rate this:
Please Sign up or sign in to vote.
Case may come when your client demand PASSWORD HERE to be displayed in readable format in your textbox for password
<html>
<head>
<title>Type of textbox from text to password</title>
<script type="text/javascript" language="javascript">
function trial()
{
    document.getElementById("txtTempBox").style.display="none";
    document.getElementById("txtPassword").style.display="";
    document.getElementById("txtPassword").focus();
}
</script>
</head>
<body>
<input type="text" id="txtTempBox" name="txtTempBox" value="Password Here" onfocus="trial();"/>
<input type="password" id="txtPassword" name="txtPassword" style="display:none;"/>
</body>
</html>

Note1 : 'type' property of textbox control, if we are trying to set it from 'text' to 'password' on an event like onfocus or onenter,it fails in IE and some other browsers. So this is the only easy method to get the work done.

Note2 : We can use 'display' and 'visibility' property of textbox style to make the textbox hidden. But if we are using 'visibility:hidden' then the textbox will be taking the space though invisible creating design issues..so only way is to go for 'display:none'.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

arunpthampi
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralThough SCRIPT DEBUGGING is DISABLED it works.I did test it i... Pin
arunpthampi22-Jul-10 23:06
memberarunpthampi22-Jul-10 23:06 
GeneralReason for my vote of 1 Rather a temporary solution, nothing... Pin
j03x222-Jul-10 2:57
memberj03x222-Jul-10 2:57 
GeneralGood one but it will fail if JavaScript is turned off. Pin
KunalChowdhury21-Jul-10 8:07
mvpKunalChowdhury21-Jul-10 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 21 Jul 2010
Article Copyright 2010 by arunpthampi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid