Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, I've decided to write my own solution that works in all major browsers (except Safari, but more on that later). Basically, how it'd work is that you assign a class to the last "tab-able" element in your form, which is usually the submit button, called 'lastInForm'. Simple HTML would look like this:</p> <pre><code>&lt;form action="action.php"&gt; &lt;fieldset&gt;&lt;input id="input1" name="input1" type="text" placeholder="text here" /&gt;&lt;/fieldset&gt; &lt;fieldset&gt;&lt;input id="input2" name="input2" type="text" placeholder="text here" /&gt;&lt;/fieldset&gt; &lt;fieldset&gt;&lt;input id="input3" name="input3" type="text" placeholder="text here" /&gt;&lt;/fieldset&gt; &lt;button class="lastInForm" type="submit"&gt;I'm last&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Using the latest version of jQuery, I listen to the keydown event for that .lastInForm element and check for the keyCode 9, which corresponds to the tab-key. When I receive that event, I look up the closest form element, look up the first input element in said form, and apply focus to it. </p> <p>Like so:</p> <pre><code>$(document).ready(function(evt){ $('.lastInForm').live('keydown', function(evt){ if(evt.keyCode === 9){ evt.preventDefault(); var form = $(this).closest('form'); var input = $('input:first', form); if(input !== undefined){ input.focus(); } } }); }); </code></pre> <p>... which results neatly in a form where you can loop through the elements using the tab key. </p> <p>Now I mentioned earlier that it works on all major browser except Safari. The reason for this is that Safari by default doesn't allow you to tab to any element except textfields. To enable this behavior you have to go and check:</p> <pre><code>Preferences &gt; Advanced &gt; Universal Access: Press Tab to highlight each item on a webpage. </code></pre> <p>Why Apple has chosen to disable such a helpful accessibility feature by default is beyond me, but all I know is if a user enables this setting my script will work for them too.</p>
    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. This table or related slice is empty.
    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