Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't care about supporting Opera, this is easy:</p> <pre><code>textbox.onkeydown = function(e) { if (e.keyCode == 38) { incrementTextBox(); } } </code></pre> <p>However, Opera doesn't fire <code>keydown</code> for key repeats... you'll have to mimic that by calling <code>incrementTextBox()</code> at an interval, and stopping when the key is lifted. I tested this in WebKit (Chrome 6.0), FF3, Opera 10.6, IE7, IE8, IE9, even IE Quirks:</p> <pre><code>var textbox = null; window.onload = function() { var timeoutId = null; var intervalId = null; var incrementRepeatStarted = false; function startIncrementKeyRepeat() { timeoutId = window.setTimeout(function() { intervalId = window.setInterval(incrementTextBox, 50); }, 300); } function abortIncrementKeyRepeat() { window.clearTimeout(timeoutId); window.clearInterval(intervalId); timeoutId = null; intervalId = null; } function endIncrementKeyRepeat() { abortIncrementKeyRepeat(); incrementRepeatStarted = false; } textbox = document.getElementById("incrementer"); textbox.onkeydown = function(e) { e = e || window.event; if (e.keyCode == 38) { if (!incrementRepeatStarted) { startIncrementKeyRepeat(); incrementRepeatStarted = true; } else if (timeoutId || intervalId) { abortIncrementKeyRepeat(); } incrementTextBox(); } else if (incrementRepeatStarted) { endIncrementKeyRepeat(); } } textbox.onkeyup = endIncrementKeyRepeat; } function incrementTextBox() { var val = parseInt(textbox.value) || 0; val++; textbox.value = val; } </code></pre>
    singulars
    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.
    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