Javascript examples for Language Basics:HTML
Display a message based on user input:
<!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>