In my code example when you put your cursor in one of the two input fields and then press ENTER on your keyboard, a timestamp number is displayed in a div underneath. Press ENTER again and it changes.
If you take one of the text fields out so there's only one, then form seems to post (reload the page).
I can't figure out why this happens when there's only one input field.
function handleKeyPress(event) {
if (event.keyCode == 13)
document.getElementById('theButton').click();
}
function theFunc() {
document.getElementById("theTime").innerHTML = Math.floor(Date.now());
}
<form>
<input type="text" name="textInput" onKeyPress="handleKeyPress(event)"><br>
<input type="text" name="textInput2" onKeyPress="handleKeyPress(event)"><br>
<input type="button" value="Submit" id="theButton" onclick="theFunc()">
</form>
<div id="theTime"></div>