Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like there are a couple of things going on. First, as <a href="https://stackoverflow.com/users/726938/jayp">jayp</a> points out in his comment, you aren't defining what <code>myText</code> is.</p> <p>Secondly, I think you're over-complicating this a bit. How about trying something like this:</p> <p>Give your text input an <code>ID</code>, something like <code>&lt;input type="text" id="myText" /&gt;</code></p> <p>Then use something like this:</p> <pre><code>// Assign our text input to a variable var myText = document.getElementById("myText"); // Capture keyDown events myText.onkeydown = function(e) { // "38" is the up arrow key if (e.keyCode == 38) { // increment the value in the text input myText.value++; // "40" is the down arrow key } else if (e.keyCode == 40) { // decrement the value in the text input myText.value--; } } </code></pre> <p>This is a pretty simplified example, but should get you pointed in the right direction. Hope it helps.</p> <p><a href="http://jsfiddle.net/bVJYF/" rel="nofollow noreferrer">See a working example at JSFiddle</a></p> <p><strong>Edit:</strong></p> <p>It's not working in your case because the script is trying to find the <code>input</code> element <em>before</em> the page is fully loaded. You can move your script to the bottom of the page like this:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;input type="text" id="myText" /&gt; &lt;script type="text/javascript" src="number.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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