<form name="game"> <input id="number" type="text"> <input type="submit" value="OK"> </form>
var form = document.forms.game; var number = 5; form.onsubmit = function() { var value = form.elements.number.value; if(value === '' || isNaN(+value)) { alert('Введите число!'); } else if(+value === number) { alert('Вы угадали!'); } else { alert(+value < number ? 'Больше' : 'Меньше'); } return false; };
form.onsubmit = function(e) { e.preventDefault(); //...
document.addEventListener('DOMContentLoaded', function() { //code });