Popup not working

I’m trying to create a pop up box that asks for a password but I can’t seem to get it to work. I’ve got this

function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
if (pass1.toLowerCase() == "password") {
var pass1 =
prompt('Access Denied - Sorry you don't have access to this page','Password');
if (pass1.toLowerCase()!="password" & testV ==3)
return " ";

With the button looking like this

<a class="btn btn-restricted" id="passWord">Protected Access</a>

I’ve not getting any errors at all but the popup isn’t working either. I’ve checked and popups isn’t disabled either.

you haven’t assigned a click handler to the button. so javaScript doesn’t know that it shall execute the function when a user clicks on the button.

You need to make your button like this:

<a class=“btn btn-restricted” id=“passWord” onclick=“passWord()”>Protected Access</a>

Brilliant thank you, I had originally added that but removed it because it was throwing errors. But I think the problem was that I was originally using don’t in the alert rather than do not.


either that or you define the handler in JS (so you don‘t have to search the whole HTML code for handlers).

document.getElementById('password').addEventListener('click', passWord, false);

Thanks I’ll try that