<form> <fieldset> password: <span id="capsalert">caps lock = on</span><br> <input type="password" id="pwd"> <script type="text/javascript"> document.write( '<input type="checkbox" name="masking" onclick="unmask(this.checked)"> ' + 'show password type' ); </script> <br> password2:<br> <input type="password" id="pwd2"> </fieldset> </form> <script type="text/javascript"> function chkcaps(e) { ev = (e ? e : window.event); kc = (ev.which ? ev.which : (ev.keycode ? ev.keycode : false)); sk = (ev.shiftkey ? ev.shiftkey : (ev.modifiers ? !!(ev.modifiers & 4) : false)); if( (kc >= 97 && kc <= 122 && sk) || (kc >= 65 && kc <= 90 && !sk) ) { document.getelementbyid('capsalert').style.display = 'inline'; } else { document.getelementbyid('capsalert').style.display = 'none'; }//end if }//end function function unmask(truefalse) { oldelem = document.getelementbyid('pwd'); elem = document.createelement('input'); elem.setattribute('type', (truefalse == true ? 'text' : 'password')); elem.setattribute('value', document.getelementbyid('pwd').value); elem.id = 'pwd'; oldelem.parentnode.replacechild(elem,oldelem); document.getelementbyid('pwd').onkeypress = function(e) { chkcaps(e); }; }//end function document.getelementbyid('pwd').onkeypress = function(e) { chkcaps(e); }; </script>
i'm using above code in more complex form.
i have 2 separate "password" fields on form. current code can have first password field show characters typed when checkbox ticked.
also, code notifies user if typing caps lock enabled.
i have both password fields exhibiting same behavior rather first field only. unfortunately, not know how make happen.
thanks help.
edit:
simple solution might easier find following code. i'm willing use either one.
<script> function changetype() { document.myform.pass.type=(document.myform.option.value=(document.myform.option.value==1)?'-1':'1')=='1'?'password':'text'; } </script> <body> <form name="myform"> <input type="password" name="pass" /> <input type="password" name="pass2" /> <input type="checkbox" name="option" value='1' onchange="changetype()" /> </form> </body>
why don't change type
attribute of password inputs in unmask()
function? way easier manage more 1 field. after checking whether have turn input
text
1 or password
one, this:
// suppose 'new_type' either 'text' or 'password' // , 'pwd' , 'pwd2' id attributes // both of password fields document.getelementbyid('pwd').type = new_type; document.getelementbyid('pwd2').type = new_type;
Comments
Post a Comment