i have a table with the fields username , password , email and phone . but the display page should show the value off the password as * . only when editing it should show the value ! Eg: take my password as pass1234 it should be displayed in list page as *** but wen editing it it should show as pass1234 . how can i do that ?
2 Answers
This requires some Javascript onfocus handler:
field = document.getElementById('pass');
field.onfocus(function() { this.setAttribute('type','text'); });
field.onblur(function() { this.setAttribute('type', 'password'); });
2 Comments
Bergi
What's
setAttr; never heard of that method? Also, you forgot to mention that this does not work in IENedStarkOfWinterfell
Sorry, that was a mistake. And regarding IE, he can replace it with
this.type = 'text'.You should only show the password in plaintext when the user asks for it, e.g. by clicking a button. What do you think the asterisks are good for?
However, you can't just set the type of the input, because IE does not allow that. So you will need to completely replace the element. For
<input name="pw" id="pw" type="password"></input>
<label><input id="plain" type="checkbox"></input>Show plaintext</label>
the JS would look like this (using jQuery for event attaching and co, you should be able to adapt this if you need):
$("#plain").change(function() {
var pw = $("#pw"),
type = this.checked ? "text" : "password";
if (type == pw.prop("type")) return;
$("<input>", {name: "pw", id:"pw", type:type}) // could be done programatically
.val(pw.val())
.replaceAll(pw);
});
1 Comment
NedStarkOfWinterfell
Oh, I did not know that. As usual, IE comes out to be a pain in the a**!
<table>with columns for the name, password, email and phone of one user?