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')
{
obj.setAttribute('type','password');
}else{
obj.setAttribute('type','text');
}
obj.focus();
Code:
<input type="text" name="password" value="Password" onclick="replaceT(this);">
Saves already entered text and everything =)
Quote:
Originally Posted by Kor
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">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script type="text/javascript">
function replaceT(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
obj.parentNode.replaceChild(newO,obj);
newO.focus();
}
</script>
</head>
<form>
<input type="text" name="password" value="Password" onfocus="replaceT(this)">
</form>
</body>
</html>
|