You are viewing an old revision of this post, from November 26, 2015 @ 15:28:52. See below for differences between this version and the current revision.

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

Figured this out:
<input type="text" id="txtSearch" onkeypress="return searchKeyPress(event);" />
<input type="button" id="btnSearch" Value="Search" onclick="doSomething();" />

<script>
function searchKeyPress(e)
{
    // look for window.event in case event isn't passed in
    e = e || window.event;
    if (e.keyCode == 13)
    {
        document.getElementById('btnSearch').click();
        return false;
    }
    return true;
}
</script>

Revisions

  • November 26, 2015 @ 15:28:52 [Current Revision] by admin
  • November 26, 2015 @ 15:28:52 by admin

Revision Differences

There are no differences between the November 26, 2015 @ 15:28:52 revision and the current revision. (Maybe only post meta information was changed.)

No comments yet.

Leave a Reply