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

<SCRIPT>
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "password") {
window.open('/resources_admin');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Sorry you don't have access to this page','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>

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.

Thanks

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