In this article, you will learn how to find out what character key is pressed in Javascript?
<div class="form-group col-md-6">
<label for="First_Name">First Name <span class="text-danger">*</span></label>
<input class="form-control" id="txt_First_Name" type="text" name="txt_First_Name" placeholder="Enter First Name" onkeypress="return searchKeyPressByName(event);" />
</div>
<div class="form-group col-md-12 text-center">
<button class="btn btn-primary" type="button" id="btn_searchByName" name="btn_searchByName">Search</button>
</div>
<script>
function searchKeyPressByName(e) {
e = e || window.event;
if (e.keyCode == 13) {
alert(e.keyCode)
document.getElementById('btn_searchByName').click();
return false;
}
return true;
}
</script>
How to find out what character key is pressed in Javascript?
minify code