How to do this through the tag itself change type from text to password
<input type='text' name='pass' />
Is it possible to insert JS inside the input tag itself to change type='text' to type='password'?
How to do this through the tag itself change type from text to password
<input type='text' name='pass' />
Is it possible to insert JS inside the input tag itself to change type='text' to type='password'?
Try:
This is not supported by some browsers (IE if I recall), but it works in the rest:
or
I had to add a '.value' to the end of Evert's code to get it working.
Also I combined it with a browser check so that input type="number" field is changed to type="text" in Chrome since 'formnovalidate' doesn't seem to work right now.
Yes, you can even change it by triggering a event
Changing the
type
of an<input type=password>
throws a security error in some browsers (old IE and Firefox versions).You’ll need to create a new
input
element, set itstype
to the one you want, and clone all other properties from the existing one.I do this in my jQuery placeholder plugin: https://github.com/mathiasbynens/jquery-placeholder/blob/master/jquery.placeholder.js#L80-84
To work in Internet Explorer:
The function below accomplishes the above tasks for you: