JavaScript on the Enter key in a text box and Value Submit | Trigger a Button Click on Enter

<input id=”xxInput” value=”Some text..”>
<button id=”xxBtn” onclick=”javascript:alert(‘Hello Sam!’)”>Button</button>

<script>
var input = document.getElementById(“xxInput”);
input.addEventListener(“keyup”, function(event) {
    event.preventDefault();
    if (event.keyCode === 13) {
        document.getElementById(“xxBtn”).click();
    }
});
</script>

More Details: Click

Leave a Reply