Home>> JQuery >>Trigger a button click with JavaScript on the Enter key in a text box
<input type="text" id="txtSearch" onkeypress="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();
}
}
</script>
Or
function searchKeyPress
(event) {
if (event.which == 13) {
document.getElementById('<%=btnSearch
.ClientID %>').click();
}
}
![]()
Hello! I'm Krishan Kumar Singh author, .NET Framework and have more than 6+ years of hand over Microsoft .NET technologies.
|