![]() |
Change input type="text" to input type="password"
I need to change input type="text" to input type="password" via JavaScript
Code:
<form id="login" action="#" method="post">Code:
<script type="text/javascript">Please can somone help! |
erm.... question, why would you want to show a text box but as soon as they start typing away it changes to a password box?????
|
I want the Box to say the word "Password" but as you click it and start typing you password is not shown :)
|
ok in that case do something like this....
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">also what is this part for? passit(this.form[0]); |
Not 100% sure
Found that code on another forum http://www.dynamicdrive.com/forums/s...ad.php?p=72456 |
IE does not like to change dynamically the type, thus one solution might be to replace entirely the object. Even so, IE does not focus first time the element, as it should, but I guess this would be a minor inconvenience:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
Thanks Kor
It is a shame there is not an easy "perfect" solution |
To get IE to focus on the new element, just have a short timeout...
Code:
function replaceT(obj){ |
can you put one on top of the other with z index/layers?
|
Quote:
that way you give the illusion of the word password in the box but it never is plus you dont need to use long JS code as shown earlier! I think that is the easiest way of doing it, no messing no fuss a simple class change |
Quote:
|
Quote:
|
The JavaScript solution is a good solution but sometimes creating a entirely new form object can create some problems, I used this solutions instead:
Code:
if(obj.getAttribute('type')=='text')Code:
<input type="text" name="password" value="Password" onclick="replaceT(this);">Quote:
|
Quote:
|
| All times are GMT +1. The time now is 08:22 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.