Text field to require 1 specific number

Hi, I have a simple form with a sum.

Sum is 4 + 1 = … the answer will of course be 5.

Does any one know of a simple tutorial where a specific number can be entered into a text field. If number is incorrect it pops up a simple error box.

Any help would be great. Thanks

<form action="..." id="my-form">
  <div>
    <label for="sum">Sum is 4 + 1 =</label>
    <input type="text" id="sum">
    <input type="submit" value="Submit">
  </div>
</form>
var form = document.getElementById("my-form");
form.onsubmit = function () {
    var sum = document.getElementById("sum");
    if (sum.value !== "5") {
        alert("Wrong answer!");
        return false;
    }
    return true;
};

Worked an absolute charm, thank you very much :slight_smile: