Drop-down Jump Menus

Accessible scripting index | tom.me.uk home

A common example of how not to use scripting correctly is using it to trigger a select element to go to another URL, when the onchange event fires - but not providing an alternative for browsers without scripting - such as...

<select onchange="if (this.selectedIndex > 0) location.href=this[this.selectedIndex].value;">
  <option selected="selected">Select a page...</option>
  <option value="/">Home page</option>
  <option value="http://www.google.com/">Google</option>
  <option value="http://www.bbc.co.uk/">BBC</option>
</select>

Which produces results such as (this select will not navigate away from this page)...

The Problem

If you don't have scripting, a menu such as the above one will do nothing. The user will be able to change the selected option, but it will not go anywhere - which will result in one very confused user.

I have seen several sites that use such a method as the only way of navigating around the site, and therefore are completely unusable and useless without scripting.

The Solution

Very simple, use your old friend the noscript element. Either...

A Button for All

Using onchange to trigger navigation does have a few disadvantages, however. If the user attempts to change the selected option using the keyboard only, Internet Explorer on Windows only allows the user to select the second option, before the navigation occurs. You can resolve this simply by providing a "go" button for all users:

<form method="get" action="myRedirectorScript.cgi" onsubmit="if (this.url.selectedIndex > 0) location.href=this.url[this.url.selectedIndex].value;">
  <select name="url">
    <option selected="selected">Select a page...</option>
    <option value="/">Home page</option>
    <option value="http://www.google.com/">Google</option>
    <option value="http://www.bbc.co.uk/">BBC</option>
  </select>
<input type="submit" value="go" title="Go to the page selected">>
</form>

Back to Contents - Articles Copyright © Tom Gilder 2002