Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6969817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:37:46+00:00 2026-05-27T16:37:46+00:00

I have a basic quantity field and would like to allow the user to

  • 0

I have a basic quantity field and would like to allow the user to increase/decrease the number within this input box based on the keyboard up/down.

Following on from: EndangeredMassa answer on keyboard code https://stackoverflow.com/a/375426/560287 how would I add this into a keyup function?

var keynum = 0;

if(window.event) { keynum = e.keyCode; }  // IE (sucks)
else if(e.which) { keynum = e.which; }    // Netscape/Firefox/Opera

if(keynum == 38) { // up
    //Move selection up
}

if(keynum == 27) { // down
    //Move selection down
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:37:47+00:00Added an answer on May 27, 2026 at 4:37 pm
    //cache our input since we will be working with it each time an arrow key is pressed
    var $input = $('input');
    
    //bind the the `keydown` event for the `document` object which will catch all `keydown` events that bubble up the DOM
    $(document).on('keydown', function (event) {
    
        //up-arrow (regular and num-pad)
        if (event.which == 38 || event.which == 104) {
    
            //make sure to use `parseInt()` so you can numerically add to the value rather than concocting a longer string
            $input.val((parseInt($input.val()) + 1));
    
        //down-arrow (regular and num-pad)
        } else if (event.which == 40 || event.which == 98) {
            $input.val((parseInt($input.val()) - 1));
        }
    });
    

    Here is a demo: http://jsfiddle.net/QRNP8/1/

    Note that jQuery normalizes the charCode/keyCode properties into event.which:

    Query normalizes the following properties for cross-browser
    consistency:

    target
    relatedTarget
    pageX
    pageY
    which
    metaKey
    

    Source: http://api.jquery.com/category/events/event-object/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic quiz/survey type application I'm working on, and I'd like to
When a user moves the Google map, I would like to display items in
I have basic idea about running PHP in different configurations like mod_php, cgi, FastCGI,
It seems like most of the messaging systems I've looked at have basic, if
For example I have a xml like <books> <book id=1> <title id=11 name=Basic XML/>
I have an array of objects that looks like this: [#<Holding id: 5, user_id:
I have basic functionality for sending a user to the moon: #Action in a
I have two divs, whose heights I would like to control relative to each
I have basic markup for a drop down nav, nested lists. The user will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.