Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no simple programmatic way to do this using Javascript... so here's a brute force way.</p> <p><a href="http://www.w3.org/TR/html4/interact/forms.html#tabbing-navigation" rel="noreferrer"><strong>According to W3</strong></a>:</p> <blockquote> <p>Elements that may receive focus should be navigated by user agents according to the following rules:</p> <ol> <li>Those elements that support the tabindex attribute and assign a positive value to it are navigated first. Navigation proceeds from the element with the lowest tabindex value to the element with the highest value. Values need not be sequential nor must they begin with any particular value. Elements that have identical tabindex values should be navigated in the order they appear in the character stream. </li> <li>Those elements that do not support the tabindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the character stream. </li> <li>Elements that are disabled do not participate in the tabbing order.</li> </ol> </blockquote> <p>I accomplished this by storing the order of elements in the form that have <code>tabIndex &gt; 0</code> in their tabIndex order and then concatenating the rest of the elements in the order they appear within the document. The following code simulates a tab keypress when focused on a form input and the letter 'z' is pressed (but you can change this to whatever condition you require):</p> <pre><code>$(':input').keypress(function(e){ // if 'z' pressed if (e.which == 122) { // if we haven't stored the tabbing order if (!this.form.tabOrder) { var els = this.form.elements, ti = [], rest = []; // store all focusable form elements with tabIndex &gt; 0 for (var i = 0, il = els.length; i &lt; il; i++) { if (els[i].tabIndex &gt; 0 &amp;&amp; !els[i].disabled &amp;&amp; !els[i].hidden &amp;&amp; !els[i].readOnly &amp;&amp; els[i].type !== 'hidden') { ti.push(els[i]); } } // sort them by tabIndex order ti.sort(function(a,b){ return a.tabIndex - b.tabIndex; }); // store the rest of the elements in order for (i = 0, il = els.length; i &lt; il; i++) { if (els[i].tabIndex == 0 &amp;&amp; !els[i].disabled &amp;&amp; !els[i].hidden &amp;&amp; !els[i].readOnly &amp;&amp; els[i].type !== 'hidden') { rest.push(els[i]); } } // store the full tabbing order this.form.tabOrder = ti.concat(rest); } // find the next element in the tabbing order and focus it // if the last element of the form then blur // (this can be changed to focus the next &lt;form&gt; if any) for (var j = 0, jl = this.form.tabOrder.length; j &lt; jl; j++) { if (this === this.form.tabOrder[j]) { if (j+1 &lt; jl) { $(this.form.tabOrder[j+1]).focus(); } else { $(this).blur(); } } } } }); </code></pre> <h2><a href="http://jsfiddle.net/SbtDM/" rel="noreferrer">See demo</a></h2>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload