[javascript] Trigger a button click with JavaScript on the Enter key in a text box

In jQuery, you can use event.which==13. If you have a form, you could use $('#formid').submit() (with the correct event listeners added to the submission of said form).

_x000D_
_x000D_
$('#textfield').keyup(function(event){_x000D_
   if(event.which==13){_x000D_
       $('#submit').click();_x000D_
   }_x000D_
});_x000D_
$('#submit').click(function(e){_x000D_
   if($('#textfield').val().trim().length){_x000D_
      alert("Submitted!");_x000D_
   } else {_x000D_
    alert("Field can not be empty!");_x000D_
   }_x000D_
});
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<label for="textfield">_x000D_
Enter Text:</label>_x000D_
<input id="textfield" type="text">_x000D_
<button id="submit">_x000D_
Submit_x000D_
</button>
_x000D_
_x000D_
_x000D_