<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>Submit input using Enter ESC or onblur</title>
<script>
function submit_input()
{
document.getElementById("msg").innerHTML = "Input "+document.getElementById("textin").value+" submited";
}
</script>
</head>
<body>
<div align="center">
<input id="textin" type="text" placeholder="Activate by Eneter or click outside the input">
<br><br><br>
<div id="msg"></div>
</div>
<script>
// This part is in the body after the input declaration above
var in1 = document.getElementById("textin");
in1.onblur = function(){ submit_input();}; // exit the input cell
in1.onkeydown = function(e) {
if (e.keyCode == 13) {
submit_input(); // pressing Enter
} else
if (e.keyCode == 27) {
document.getElementById("textin").value = ""; // pressing ESC
}
};
</script>
</body>
</html>