You need to do it in pure JavaScript, because everything else would be too time-consuming.
The basics of it is this: you can focus any element by your code:
http://www.w3schools.com/jsref/met_html_focus.asp[
^].
See the code sample: you get a DOM element by its
id
and then focus it. And, to invoke it, you would need to handle the event
onkeydown
on each control. Of course, doing it by writing some unique
id
values and event handler to each and every control would be too tedious and too much of ad hoc. But first, you don't need to cover all controls by this mechanism, recursively. For this, universal action you can still use the TAB. Most likely, you only need to cover some required set of controls, for example, all controls on some form, or something like that.
Fortunately, you can use some library, such as jQuery. You can add event handler to each control during runtime, without writing event attributes in HTML text. Here is how:
http://api.jquery.com/keydown/[
^].
Likewise, you don't have to write the
id
in all controls. For this mechanism, you won't need IDs at all. Instead, you can do the loop by, say, all children of some parent element (such as
<form>
), and, for each control encountered, add an event handler and put a DOM element reference to some array. In your event handle, you will move the focus backward or forward in the array (don't forget to loop it, if you need to). This is how you can do the loop:
http://api.jquery.com/each/[
^].
And this is how you can you get children:
http://api.jquery.com/children/[
^].
So, you can get all children and traverse some code through all of them. For other traversing methods, please see:
http://api.jquery.com/category/traversing/[
^].
One trick is this: you will need to find out of some element can be focused or not. Apparently, you won't need to try to shift focus to some element which is not a control, or disable, or not focusable by whatever reason; you should skip non-focusable elements until you get the first one to focus on. Here is how:
http://api.jqueryui.com/focusable-selector/[
^].
I think you now have all you would need. If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[
^],
http://jquery.com/[
^],
http://learn.jquery.com/[
^],
http://learn.jquery.com/using-jquery-core/[
^],
http://learn.jquery.com/about-jquery/how-jquery-works/[
^] (start from here).
—SA