View Full Version : Prompt Type

11-15-2009, 08:04 PM
Is there a type setting with the prompt function for password, or anything similar?

11-15-2009, 10:03 PM
I'm not sure I understand. The javascript prompt() method (as far as I know) only accepts one data type, string.

If you want the results of a javascript prompt to become a password, you could have its return value set the value property of an input element of the type 'password'. But when entered into the prompt, it will still be 'echoed' (seen while entered into the prompt's input line) back to the user.

If you want to prompt for a password that will not be seen when entered (instead represented by fat dots), use an .htaccess file or some other server side mechanism designed for that.

If you really need to use javascript for this, you could pop up a previously unseen division that contains a password input. But, if this at all needs to be secure, there would have to be something iron clad behind it on the server side, and ideally a server side fall back for non-javascript enabled users.

11-15-2009, 10:49 PM
I'm making a file uploader for three users (all with javascript enabled). I was wondering if like the html input field the prompt had types like "button", "text", "password", etc. But it sounds like a no there. I'm using the onload feature to launch a prompt before the page loads it's content. Thanks.

Edit: Figured out second question.

function getpass() {
var pass = prompt("Input Password to Upload files");
if (pass =="" || pass == "null") {
document.cookie = "password=" + "NOTSET";
document.getElementById('show').style.display ='none';
} else {
document.cookie = "password=" + pass;
document.getElementById('show').style.display ='block';

<body onload="getpass(); return false;">

11-16-2009, 08:11 AM

if (pass =="" || pass == "null")

can be:


But anyways, this whole business stinks. I could enter no password, then paste this into the address bar:

javascript:void(document.getElementById('show').style.display ='block')

hit enter, and viola! I would have access to the 'protected' content.

11-16-2009, 04:12 PM
See also:


11-17-2009, 05:28 PM
Okay, I wasn't planning on having secure data on this page I was going to pass it to a server side page additionally, I've ended up just doing the whole thing server side though. Do you know where there's a good javascript tutorial, preferably with working demos? Thanks.

11-17-2009, 06:17 PM
I'm not really aware of any good sites with demos. That's not to say that there aren't any. There's w3schools, but they don't really tie it all together very well and miss a lot of the fine points.

This book:

Object-Oriented JavaScript
by: Stoyan Stefanov
publisher: PACKT

is pretty good, though not perfect. It's biggest problem is that it doesn't always (though it usually does) identify when something doesn't work in some browsers. It does however do a good job on tying things together and on many of the important fine points. It is complete with examples and exercises you can try out. Some of it (mostly for simple concepts) employs the Firefox Firebug extension, but you don't need that. I have Firebug but don't use it or know it very well. You just have to understand that when the author is using it to explain things, which he does a lot with real simple ideas, that typing it into the Firebug console is just a little different than coding it right to the page would be.

If the book is a bit pricey for you (I got a review copy), you can go to the publisher's page and get the .PDF version for considerably less. For trying out the code, PDF is actually better because you can cut and paste from it. Also, it (the actual book) may be available at a reduced price from some vendors.