?
Solved

Keyboard control of drop down list

Posted on 2012-03-24
2
Medium Priority
?
454 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 1500 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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

777 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