Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryManaging Website Forms

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Tab-friendly Forms

Use the "tabindex" attribute to make forms user-friendly.

For people who use the tab key for navigating from one form field to another, a random or unexpected tab order can be frustrating.

The tab key can navigate all visible form fields, including radio buttons, checkboxes, and selection lists.

Without the tabindex attribute, the tabbing order is the order of the visible form fields in the source code. This includes radio buttons and dropdown lists. (If the tabindex attribute is used elsewhere on the page it is likely to interfere with the tab order of the form.)

To control the tab order, use the tabindex attribute. The attribute can also be used to prevent fields from being tabbed into.

The tabindex attribute can even be used to specify a tab order spanning two or more forms.

Specifying a Tab Order

Below is an example of the tabindex attribute being used to control the tab order.

The source code order is:

  • The name field.
  • The checkbox.
  • The email field.
  • The submit button.

The tabindex attribute is used to change the tab order to:

  • The name field.
  • The email field.
  • The checkbox.
  • The submit button.

Click the name field then press the tab key three times, noticing where the cursor goes after each tab press.

Name
  Good to go!
Email
 

Note: The tabindex attribute values can't be repeated for the live examples without interfering with each other. It means continuing to press the tab key will move the cursor to the next example.

Here is the source code for the above example:

<div style="border:1px solid black; padding:10px; width:205px;">
<form onsubmit="return false;">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>Name</td>
   <td><input tabindex="1" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="3" type="checkbox" name="good_to_go">Good to go!</td>
</tr><tr>
<td>Email</td>
   <td><input tabindex="2" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="4" type="submit" value="Let's get started." style="width:151px;"></td>
</tr>
</table>
</form>
</div>

The tabindex attributes and their values in the source code are blue.

Preventing a Field from Being Tabbed Into

To prevent a field from being tabbed into, specify a value of -1 for the tabindex attribute. The tabindex="-1" attribute may be specified in more than one field.

This example prevents the checkbox field from being tabbed into. Click the name field then press the tab key twice, noticing where the cursor goes after each tab press.

Name
  Good to go!
Email
 

Below is source code to replicate the above example.

<div style="border:1px solid black; padding:10px; width:205px;">
<form onsubmit="return false;">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>Name</td>
   <td><input tabindex="1" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="-1" type="checkbox" name="good_to_go">Good to go!</td>
</tr><tr>
<td>Email</td>
   <td><input tabindex="2" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="3" type="submit" value="Let's get started." style="width:151px;"></td>
</tr>
</table>
</form>
</div>

The tabindex attributes and their values in the source code are blue.

A Tab Order Spanning Two Forms

Using the tabindex attribute, the tab order for these two forms is specified as:

  1. Left form, name field.
  2. Right form, name field.
  3. Left form, email field.
  4. Right form, email field.
  5. Left form, checkbox.
  6. Right form, checkbox.
  7. Left form, submit button.
  8. Right form, submit button.

Click the name field of the left form then press the tab key seven times, noticing where the cursor goes after each tab press. (If these two forms were the only forms on the page, you could simply tab to begin instead of clicking)

Name
Good to go!
Email
Name
Good to go!
Email

Here is source code to replicate the above example.

<div style="float:left; border:1px solid black; padding:10px; width:205px;">
<form onsubmit="return false;">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>Name</td>
   <td><input tabindex="1" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="3" type="checkbox" name="good_to_go">Good to go!</td>
</tr><tr>
<td>Email</td>
   <td><input tabindex="5" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="7" type="submit" value="Let's get started." style="width:151px;"></td>
</tr>
</table>
</form>
</div>

<div style="float:right; border:1px solid black; padding:10px; width:205px;">
<form onsubmit="return false;">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>Name</td>
   <td><input tabindex="2" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="4" type="checkbox" name="good_to_go">Good to go!</td>
</tr><tr>
<td>Email</td>
   <td><input tabindex="6" type="text" name="name" style="width:145px;"></td>
</tr><tr>
<td> </td>
   <td><input tabindex="8" type="submit" value="Let's get started." style="width:151px;"></td>
</tr>
</table>
</form>
</div>

<div style="clear:both;"></div>

As in the other examples, the tabindex attributes and their values in the source code are blue.

Use the tabindex attribute to make your forms user friendly. People who use the tab key for navigating form fields will appreciate it.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC