Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keyboard control of drop down list

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 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