How can I make a search button clickable by pressing the Enter key?
Here is the HTML code that I am using:
<input type="text" runat="server" id="txtSearch" onkeypress="searchKeyPress(event);"
<input type="button" runat="server" style="padding:5px;" id="butSearch" onserverclick="butSearch_Click" value="Search" disabled/>
This is the JavaScript function that I have implemented:
function searchKeyPress(e) {
if (typeof e == 'undefined' && window.event) { e = window.event; }
if (e.keyCode == 13) {
document.getElementById("butSearch").click();
}
}
However, I am encountering the following error:
'Uncaught TypeError:Cannot call method click of null'
Can you provide advice on why I am receiving this error and suggest a better alternative to achieve this functionality?