Display a message based on user input: - Javascript Language Basics

Javascript examples for Language Basics:HTML

Description

Display a message based on user input:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input id="myInput" type="text">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w ww. ja  v  a2  s .  co  m*/
    var letter = document.getElementById("myInput").value;
    var text;

    if (letter === "c") {
        text = "C";

    } else if (letter === "b" || letter === "d") {
        text = "d or b";

    } else {
        text = "else";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials