Go Back to Dynamic Site Solutions :: JavaScript

Change Input Type Dynamically

These two scripts change an input element of type password to type text when the page is loaded. When the element receives focus it is changed back to type password; when it loses focus if no password was entered it is changed back to type text. If JavaScript is not enabled or the script detects the browser is one of the ones known to not support this, the input elements are still of type password, so they can be used normally.

Example 1 works in Firefox, Netscape 6+, Opera 9.x, Opera 7.2x through 7.5x, and Safari 1.2+. (It's very buggy in Opera 7.0x and 7.1x. It doesn't work at all in Opera 8.x or in IE/Win.) For comparison, Example 2 works in IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari 1.2+, and Konqueror 3.5. Example 2 is a little buggy in IE5/Mac, but it mostly works in this new version. Example 2 crashes Konqueror 3.3 and 3.4 and Safari 1.0. I put in a conditional to keep the script from running in those browsers. Neither works in iCab 3.

Last update: 2008-04-15