Auto-select form box

Justin R Ervin jrervin at uncg.edu
Mon Jan 12 09:24:46 EST 1998


> Is there a method to have the cursor automatically
> appear in a form box when a page is loaded?
> 
> I would like to modify the search pages on our catalog
> (DRA Web) to minimize user 'mousing'.
John, et al: Yes, there is! It's a very short JavaScript routine that you 
can easily insert into your author.html, keyword.html, etc pages.

First, make this change. Find the line of code that begins the form; on 
our pages, it's followed by two <input> tags and may look something like 
this. (Keyword.html will probably have a different action="" attribute.
<form method="GET" action="/MARION">
Change it so that it looks like this.
<form method="GET" action="/MARION" name="curse">
Visual BASIC and other programmers of object-oriented language will 
recognise the concept of naming objects.

Second, insert the following code somewhere near the end of the file. Ours 
us just after the </form> tag.

<script language="JavaScript">
        <!--
        document.curse.kwd.focus();
        //-->
</script>

Please note that this script is sensitive to line breaks/carriage returns. 
We had a bugger of a time with the incompatible ways that our various 
systems interpret line breaks. If you can't get it to work by editing it 
directly on your web server, try editing it in Window's Notepad (or some 
other plain vanilla text editor) and then FTPing it to the server. Again, 
programmers of object-oriented languages will recognise the document form, 
curse and kwd objects, and focus method. The various comment tags (<!-- 
--> for HTML and // for JavaScript prevent non-JS-enabled browsers from 
trying to interpret the JavaScript and keep JS from trying to interpret 
the HTML end-comment tag.

You may wish to have a look at the source code of our author.html 
(http://library.uncg.edu:83/author.html) and keyword.html 
(http://library.uncg.edu:83/keyword.html) files.

Unfortunately, we have been unable to make this work in other instances, 
specifically when we ask for a user's University ID to authorise their use 
of several of our databases. Still holding out hope, however, I've 
left the JavaScript code there, but commented it out. (For an example, 
look at http://library.uncg.edu:83/dbs/auth/auth-AGRICOLA.html.)

Best of luck!
=================Justin R Ervin==================
Computing Support Technician I
Jackson Library Electronic Information Resources, UNCG
jrervin at uncg.edu                 http://www.uncg.edu/~jrervin/



More information about the Web4lib mailing list