Ben Donohue
Ben Donohue

Reputation: 31

How to create a password which will reveal a hidden message in html and js

I'm new to HTML and js, and I am currently trying to make it so that the user will type in a password, and if correct, it will reveal a hidden message. This is what I got so far. I can't get it to work.

Here's the HTML:

<form id="form" onsubmit="return false;">
  <input type="text" id="userInput" />
  <input type="submit" onclick="othername();" />
</form>

<p id="hidden_clue"></p>

And here's the js:

var pass1 = 3736.62417618;
var input = document.getElementById("userInput").value;
alert(input);

if (input == pass1) {
  document.getElementById("demo").innerHTML = "Hello JavaScript!";
}

Upvotes: 3

Views: 349

Answers (1)

Carlos1232
Carlos1232

Reputation: 815

You were close, but on the getElementById you need to select the ID of the element that you want to get.

function othername() {
    var pass1 = 3736.62417618;
    var input = document.getElementById("userInput").value;

    if (input == pass1) {
        document.getElementById("hidden_clue").textContent = "Hello JavaScript!";
    }
}
<form id="form" onsubmit="return false;">
  <input type="password" id="userInput" />
  <input type="submit" onclick="othername();" />
</form>

<p id="hidden_clue"></p>

Upvotes: 2

Related Questions