mercredi 21 décembre 2016

JavaScript alert onclick onchange if statement

I am trying to display an onclick alert if the box is filled in with the world "hello", while a different alert should pop up in "hello" is not typed. Not sure what I am doing wrong here:

The HTML:

<form>
<input id="box" placeholder="type hello" onchange="sayHello()" style="display: block;" />
<input type="button" onclick="sayHelloTwo()" value="Click me" />
<p id="hidden" style="display: none;">
 HELLO
</p>
</form>

The JavaScript:

function sayHello() {
var answer = "hello";
if (answer) {
alert("Click for Hello!");
} else {
alert("you need to type hello!");
return false;
 }
}

function sayHelloTwo() {
document.getElementById("hidden").style.display = "block";
document.getElementById("hidden").style.color = "#909090";
document.getElementById("hidden").style.fontSize = "40px";
}

Aucun commentaire:

Enregistrer un commentaire