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 5975529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:05:52+00:00 2026-05-22T21:05:52+00:00

When I handle the arrow keys (up/down/left/right) using the KeyDown event of an element

  • 0

When I handle the arrow keys (up/down/left/right) using the KeyDown event of an element to set focus onto a SELECT, the SELECT which gets “focused” seems the receive a “KeyUp” event which makes it select the next/previous OPTION (depending on which arrow you pressed).

It only happens in Firefox (tested in 3 & 4), where as IE8 & Chrome work as expected (they don’t change the value of the “focused” SELECT).

The code below reproduces the issue (just press any arrow key and it will focus the other ):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>KeyUp Issue</title>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        $("select")
            .live("keydown", function(event)
            {
                switch (event.keyCode)
                {
                    case 37: // left
                    case 38: // up
                    case 39: // right
                    case 40: // down
                        $(this).siblings().focus();
                        event.preventDefault();
                        break;
                }
            })
            .live("keyup", function(event)
            {
                // This event handler makes absolutely no difference; it's still
                // "broken" in Firefox and works fine in IE/Chrome without it.
                switch (event.keyCode)
                {
                    case 37: // left
                    case 38: // up
                    case 39: // right
                    case 40: // down
                        event.preventDefault();
                        break;
                }
            })
            .live("keypress", function(event)
            {
                // This event handler makes absolutely no difference; it's still
                // "broken" in Firefox and works fine in IE/Chrome without it.
                switch (event.keyCode)
                {
                    case 37: // left
                    case 38: // up
                    case 39: // right
                    case 40: // down
                        event.preventDefault();
                        break;
                }
            });
    </script>
    <select id="select1">
        <option>One</option>
        <option>Two</option>
        <option>Three</option>
        <option>Four</option>
    </select>
    <select id="select2">
        <option>One</option>
        <option>Two</option>
        <option>Three</option>
        <option>Four</option>
    </select>
</body>
</html>
  • 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-22T21:05:53+00:00Added an answer on May 22, 2026 at 9:05 pm

    The keypress event is the one which would need to be canceled, but Firefox ignores preventDefault() in this scenario. So the solution is to blur the current dropdown, let the keypress event fire on the document and set the focus to the new dropdown via timeout.

    Demo at http://jsfiddle.net/roberkules/3vA53/

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

Sidebar

Related Questions

I've made a slider that uses the left and right arrow keys to move
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using
in jQuery-UI Slider arrow keys move the slider handle (after the handle has been
I'm using a script to make a user's keyboard control left/right slide navigation on
I handle a website which is designed in GWT and I want to check
How can I handle ArrowKeys and < (Greater Than) in a Javascript function? Which
In my Direct3D application, the camera can be moved using the mouse or arrow
I want to know the how to handle when user press up arrow when
I'm trying to make an HTML5 RPG game using easelJS to handle sprite animations.
I handle commands inside a RoutedCommand class that implements RoutedUICommand. This would help me

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.