Checking if enter key pressed in the text box <p>I am using following code to check if enter key was pressed in textbox but I am getting type error <strong>TypeError: e is undefined</strong></p> <pre><code>&lt;html lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt; &lt;title&gt;demo&lt;/title&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; function memSort(e){ if(e.keyCode === 13){ alert("Enter was pressed "); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="searchBox"&gt; &lt;div class="keyname"&gt;Keyword : &lt;/div&gt; &lt;input name="usersearch" id="usersearch" type="text" value="" onKeydown="memSort();"/&gt; &lt;div id="listOrders"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>