Note that there are some explanatory texts on larger screens.

plurals
  1. POonkeyup handler not being called
    primarykey
    data
    text
    <p>I found a post on SO that was actually posted yesterday (I cannot find it now) that says my code below should work, but it does not -- the 'handleRtnKey(e)' function below is never called - why?</p> <pre><code>&lt;input type="text" id="zer" onkeyup="handleRtnKey(e)"/&gt; // my javascript function -- by the way, I will not be using jquery. function handleRtnKey(e) { alert("Just entered handleRtnKey()"); if (!e) { e = window.event; // resolve event instance for IE } alert("Just entered handleRtnKey(), e.keyCode is: " + e.keyCode); alert("Just entered handleRtnKey(), e is: " + e); if (e.keyCode == '13') { alert("handleRtnKey: got the RTN key up event."); return false; } } </code></pre> <p>None of the alerts fire.</p> <p>I found a SO post from yesterday that had this near exact code (without my alerts) that claimed to work fine (sorry I cannot re-find that SO post).</p> <p>I need to use straight javascript (not jquery) to get the key code of the keyup event in my input text box -- that's all I need to do, and if it is the Return key, then I'll take some action, but for now I cannot get the above code to fire that handleRtnKey() function -- why?</p> <p><strong>EDIT</strong></p> <p>Damon introduced me to the keyword 'event' and the above code now works fine -- I simply renamed the argument in the html code from 'e' to 'event' and the javascript handler now works fine -- here is the only modification to the code above I had to make:</p> <pre><code> // OLD &lt;input type="text" id="zer" onkeyup="handleRtnKey(e)"/&gt; // NEW &lt;input type="text" id="zer" onkeyup="handleRtnKey(event)"/&gt; </code></pre> <p>NOTE: the javascript function handleRtnKey(e) is <em>unchanged</em>, there was no reason for my to change that function's signature, it looks like below and works fine now:</p> <pre><code>function handleRtnKey(e) { alert("Just entered handleRtnKey()"); if (!e) { e = window.event; // resolve event instance for IE } alert("Just entered handleRtnKey(), e.keyCode is: " + e.keyCode); alert("Just entered handleRtnKey(), e is: " + e); if (e.keyCode == '13') { alert("handleRtnKey: got the RTN key up event."); return false; } } THANKS DAMON. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload