Use UP/DOWN arrow keys to call a function (and passing parameter)
<p>I have a survey in which there are numerous text inputs taking numerical value each of which has a pair of increment/decrement buttons. I have a working function as follows:</p>

<p>HTML:</p>

<pre><code>&lt;div class="text-input-wrapper"&gt;
    &lt;input type="text" /&gt;
    &lt;div class="buttons inc-dec"&gt;
        &lt;button class="increment"&gt;Increment&lt;/button&gt;
        &lt;button class="decrement"&gt;Decrement&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;

function incDec(btnClass)   {

    var input       = $(this).closest('.text-input-wrapper').find('input');
    var inputVal    = $(this).closest('.text-input-wrapper').find('input').val();

    if ($(this).hasClass('increment')) {
        if (inputVal.length == 0) {
            ($(input).val('1'));
        }
        else {
            inputVal++;
            $(input).val(inputVal);
        }
    } // increment

    else if ($(this).hasClass('decrement')) {
        if (inputVal.length == 0) {
            ($(input).val('0'));
        }
        else {
            inputVal--;
            $(input).val(inputVal);
        }
    } // decrement

    return false;

} // function incDec
</code></pre>

<p>Now I need to enable incrementing and decrementing value using the UP &amp; DOWN keys; I took a stab with the following but with no joy:</p>

<pre><code>$(document).keydown( function(eventObject) {
    // UP arrow
    if(eventObject.which==38) {
        var btnClass = "increment";
    } else

    // DOWN arrow
    if(eventObject.which==40) {
        var btnClass = "decrement";
    }
    incDec(btnClass);
</code></pre>

<p>I’d greatly appreciate some clarification as to how to go about firing the increment/decrement using the up/down keys,</p>

<p>Many thanks in advance, </p>

<p>svs</p>
