View Full Version : Password mask

12-28-2006, 08:19 PM
I have a password protected page but want to mask the output when entered. Now it prompts for password but shows the input.

Please advise how I can do this:

var password = prompt("Enter your password","");
if (password == "hotsource") {
alert("Password accepted! Loading page...");

document.write("<p>data here.</p>");


else {
alert("" +password+ " is an Invalid Password! Access denied...");

document.write("<p><b>You have entered an invalid password. ");
document.write("Access to the document is denied.</b></p>");

12-28-2006, 09:15 PM

12-28-2006, 09:16 PM
Is there a reason why you want to use strictly JS?
How about HTML:

<intput type='password' onchange='validate(this.value)' />

12-28-2006, 09:18 PM
You will have to make your own equivalent to the prompt box that uses a password field. There isn't one built into Javascript. See http://javascript.about.com/library/blmodald1.htm for an example of one way to do it.