Passwords in javascript are trivial to circumvent, and in this case, they could find the password by looking at the source.

Having said that, you could trigger your code by using onclick - <div class="mymenu" onclick="password();">

EDIT: Also, (!pass1) is invalid syntax, did you mean (pass==null)?

Answer from AMADANON Inc. on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Making an alert if the user email or password is wrong - JavaScript - The freeCodeCamp Forum
January 7, 2022 - I have some code that will run when a button is clicked on another page. The code looks for the student email and password, what I am trying to do is if email is right and the password is wrong then alert that the password is wrong. If the password is right, and email is wrong then alert the ...
Discussions

php - Password in confirm box Javascript - Stack Overflow
I have a Delete button in my PHP page which deletes a record. But when I delete that button I do a confirm box with: More on stackoverflow.com
🌐 stackoverflow.com
How can I hide the password entered via a JavaScript dialog prompt? - Stack Overflow
How can I hide the password entered by a user in a dialog prompt in JavaScript? For example, using something like var passwd = prompt("Enter Password : ", "your password here"); I would like that ... More on stackoverflow.com
🌐 stackoverflow.com
HTML/Javascript - username and password - Stack Overflow
This html code below is suppose to execute and launch an alert asking for a username and if you get the username correct than it will ask for a password but nothing happens if i open this page in a browser. Why this doing this? What am I missing? Please don't tell me this is a unsecure way to do this I already know I'm just improvising until I implant a better way. More on stackoverflow.com
🌐 stackoverflow.com
Creating a basic JavaScript password prompt for webpage closure
Hey everyone! I’m working on a small project for my phone. It doesn’t have a built-in lock screen, so I want to make a simple JavaScript app to do the job. Here’s what I’m thinking: When you open the webpage, it asks for a password If you type the right password, the page closes If ... More on community.latenode.com
🌐 community.latenode.com
0
0
March 11, 2025
🌐
Reddit
reddit.com › r/learnjavascript › making alerts for incorrect username and password
r/learnjavascript on Reddit: Making alerts for incorrect username and password
January 7, 2022 -

I have some code that will run when a button is clicked on another page. The code looks for the student email and password, what I am trying to do is if email is right and the password is wrong then alert that the password is wrong. If the password is right, and email is wrong then alert the user about the email being wrong. If both password and email are wrong then alert that both are wrong. My problem right now is even if the password and email are right, I am still getting the alert that the email is wrong, and the alert that both are wrong

 onLogin(): any {
    var emailInput = (<HTMLInputElement>document.getElementById('emailInput')).value.trim();
    var passInput = (<HTMLInputElement>document.getElementById('passInput')).value.trim();
    var emailFormat = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$";
  
    if(!emailInput.match(emailFormat)){
        alert("Please enter a valid email!");
    }

    if(passInput ==''){
      alert("Password field can not be empty!");
    }
     

    for (let i = 0; i < this.Student.length; i++) {

      if (emailInput == this.Student[i].email) {
        console.log('email success');
        if (passInput == this.Student[i].password) {
          console.log('pasword success');
          //get the id
          console.log(this.Student[i]._id);
          this.studentId = this.Student[i]._id;
          localStorage.setItem("studentId", this.Student[i]._id);
          
          this.ngZone.run(() => this.router.navigateByUrl('/course-list'))
        } else if (emailInput == this.Student[i].email && passInput !== this.Student[i].password){
          alert('Password is incorrect for this email!');
          console.log('password fail');
        }
      } else if (emailInput !== this.Student[i].email && passInput == this.Student[i].password) {
        alert("Email is incorrect for this password!");
        console.log('email fail');
      }
      else if (emailInput !== this.Student[i].email && passInput !== this.Student[i].password) {
        alert("Both password and email are incorrect!");
      }
      else{
        console.log("successful login");
      }
    }
  }
🌐
W3Resource
w3resource.com › javascript › form › password-validation.php
JavaScript : Password validation - w3resource
August 19, 2022 - function CheckPassword(inputtxt) { var paswd= /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{7,15}$/; if(inputtxt.value.match(paswd)) { alert('Correct, try another...') return true; } else { alert('Wrong...!') return false; } } ... To validate the said format we use the regular expression ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$. Next the match() method of string object is used to match the said regular expression against the input value. Here is the complete web document. ... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript form valid
Find elsewhere
🌐
The Art of Web
the-art-of-web.com › javascript › validate-password
Password Validation using regular expressions and HTML5
As you can see from the screenshot above the alert message in Firefox for when the input doesn't match the pattern attribute is simply "Please match the requested format.". Not entirely helpful in this case where we have a number of different requirements. Fortunately it is possible to customise this message using just a touch of JavaScript. The only change between this and the previous example is that we've modified the onchange handler for the Password input and added one for Confirm Password: <form method="POST" action="..." onsubmit="return checkForm(this);"> <fieldset> <legend>Change Pass
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-validate-confirm-password-using-javascript
How to validate confirm password using JavaScript ? - GeeksforGeeks
July 23, 2025 - JavaScript function validate_password() is triggered on every keyup event in the password confirmation field. It compares the password and confirmation password values and provides visual feedback, disabling the submit button if the passwords ...
🌐
Quora
quora.com › How-do-I-create-a-new-popup-window-for-a-username-and-password-in-JavaScript
How to create a new popup window for a username and password in JavaScript - Quora
JavaScript (programming l... ... Web Development and Desig... ... To create a new popup window that collects a username and password in JavaScript, use a small, focused window opened with window.open and render a simple HTML form in it.
🌐
Latenode
community.latenode.com › other questions › javascript
Creating a basic JavaScript password prompt for webpage closure - JavaScript - Latenode Official Community
March 11, 2025 - Hey everyone! I’m working on a small project for my phone. It doesn’t have a built-in lock screen, so I want to make a simple JavaScript app to do the job. Here’s what I’m thinking: When you open the webpage, it asks for a password If you type the right password, the page closes If ...
🌐
ASPSnippets
aspsnippets.com › Articles › 1374 › Password-and-Confirm-Password-validation-using-JavaScript-and-jQuery
Password and Confirm Password validation using JavaScript and jQuery
August 29, 2022 - Validate JavaScript function, the values of the Password and the Confirm Password TextBoxes are fetched and are compared. If the values do not match an error message is displayed using JavaScript Alert Message Box and False value is returned in order to stop the form submission.
🌐
CodePen
codepen.io › Haagimus › pen › dPrewE
JS Password prompt
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.