[WEB4LIB] Re: javascript

Thomas Dowling tdowling at ohiolink.edu
Wed Nov 10 09:33:06 EST 1999


Andrew Mutch writes:

> Paste the following between your <HEAD></HEAD> tags.
>
> <script type="text/javascript">
> <!--
> function jmp(formnum,menunum)
> {with (document.forms[formnum].elements[menunum])
> {i=selectedIndex;location=options[i].value;}}
> // -->
> </SCRIPT>
>
> Use the following code for your form - this particular variation allows
> you to place multiple "Jump" menus on one page:
>
>
> <form name="menu" method=POST OnSubmit="return false">
> <select name="m" size=1 onChange="jmp(0,0)">
> <option selected value="">Select a Site!
> <option value="http://URL1.com">Site 1</option>
> <option value="http://URL2.org">Site 2</option>
> </select>
> <input type=submit value="Go!" onClick="jmp(0,0)">
> </form>


Being less adept at JavaScript than Andrew, I go with a cheaper kludge:

=========
<form method="GET" action="/cgi-bin/launchpad.pl">
<select class="main_nav" name="goto"
  onChange='window.location = this.options[selectedIndex].value'>
<option value="http://www.ohiolink.edu/">OhioLINK Home</option>
<option value="http://www.ohiolink.edu/db/">Research Databases</option>...
</select>
<input type="submit" value="Go">
</form>
=========


A couple of stock caveats (I know the JS gurus on the list know these, but
they're worth repeating).  First, a FORM element without an Action
attribute will not validate as HTML 4.0.  Under HTML 3.2 the Action
attribute is implied and browsers will probably assume it's the current
URL.  You can guess users' frustration levels if their browser keeps
submitting this form back to the HTML page where they got it.

Second, a form that cannot be used with scripting disabled breaks even
Level A compliance with the WCAG, meaning one or more groups of users will
find it *impossible* to use your page.  You should either find a way for
the form to work with or without scripting, or you should use a script to
write out the form itself, with a robust NOSCRIPT element providing a
complete alternative.

If you've got a lot of Javascript on your site, you owe it to yourself
(and to a non-negligible percentage of your users) to disable scripting in
your browser for a week.


Thomas Dowling
OhioLINK - Ohio Library and Information Network
tdowling at ohiolink.edu




More information about the Web4lib mailing list