Activate Submit button is correct password in given using JavaScript

<!DOCTYPE html>
    <title>Password Protected Form</title>
      <label for="password">Password:</label>
      <input type="password" id="password" name="password">
      <button type="submit" id="submit-button" disabled>Submit</button>

      // Change this variable to the correct password
      const correctPassword = "password123";

      // Get the password input and submit button elements
      const passwordInput = document.getElementById("password");
      const submitButton = document.getElementById("submit-button");

      // Add an event listener to the password input that checks if the entered password is correct
      passwordInput.addEventListener("input", ()  =>
        if (passwordInput.value === correctPassword)
          submitButton.disabled = false;
        } else 
          submitButton.disabled = true;
The arrow function in this case checks if the entered password matches the correct password. If the entered password is correct, the submit button is enabled. Otherwise, the submit button remains disabled.

Leave a Reply

Your email address will not be published. Required fields are marked *