Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript Check the answer

<form id="form">
    <input id="MyEnter" type="text" name="inputBox" placeholder="Enter your answer"><br> 
</form>

<script>
var myenter = document.getElementById("MyEnter");
myenter.addEventListener("keypress", function(event) {
  if (event.key === "Enter") {
    event.preventDefault();
    var answer = 'Hello'
    var mytext = document.getElementById("MyEnter").value;
    if (mytext==answer) {
        alert('opening another page');
        window.open("https://www.google.com");
    }else{
        alert("Incorrect answer");
    }
  }
});
</script>
 
PREVIOUS NEXT
Tagged: #javascript #Check #answer
ADD COMMENT
Topic
Name
5+2 =