Solved

Keyboard control of drop down list

Posted on 2012-03-24
2
450 Views
Last Modified: 2013-11-19
I need to control my option lists via the keyboard (for accessibility). Since I need the key navigation sequences to be the same on FF, IE, and Safari, I cannot rely on the 'accessibility' attribute.

How can I make a HTML option list 'drop down' to show its items when I tab to the option list? And then, how can I make each option list element appear as if the mouse has moved to it when I hit the tab key successively to move through the list items?

I am using JavaScript and not using any js framework like JSQuery.

Thanks in advance.

Joe
0
Comment
Question by:borgtamer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37762273
Not simple to do with a standard <select>
All browsers handle focus differently. If you will change the size of the dropdown to the number of entries, it will look like it dropped down, but it will push anything after it down.
Tabbing around will not natively want to stay in the dropdown

It was decided on our site to style the dropdown - making it a widget.
It makes it behave in any way we want, but I am worried about browsers that does not see it as a select.

Accordions are also good alternatives
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37762278
For example

DEMO

<form>
    <input type="text" />
    <select id="sel1">
        <option>One</option>
        <option>Two</option>
        <option>Three</option>
        <option>Four</option>
    </select>
    <input type="text" />
</form>    

$('#sel1').bind('keydown', function(e) {
  var keyCode = e.keyCode || e.which;
  if (keyCode == 9) {
    e.preventDefault();
    if (e.shiftKey) {
      if (this.selectedIndex>0) {
      this.selectedIndex--;
      }
    }    
    else if (this.selectedIndex<this.options.length-1) {
      this.selectedIndex++;
    }
  }
})
$('#sel1').focus(function(){$(this).trigger("click")}); // does not work in Fx

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question