Jazzing It Up: Using JavaScript to Enhance Your Library’s Webpresence
By Scott McLaren


What Exactly Is JavaScript, Anyway?

The word alone is enough to send a chill down the spines of most librarians. JavaScript sounds so complicated, so esoteric, so torturous. But if we take a closer look we discover, happily, that it isn’t any of these things. JavaScript is really nothing more than a simple programming language that web browsers like Internet Explorer and Netscape understand. And it can be used to make those browsers do all sorts of fun and functional things that they don’t normally do.

A JavaScript Taxonomy

What sorts of functionalities can JavaScripts add to your webpages? Well, most JavaScripts are designed to either enhance navigation, solicit user input, deposit cookies, issue special messages, or provide special button and graphical effects. In fact, some commercial web development packages, like Dreamweaver, have basic JavaScript functionality built right in. Others, like Microsoft Frontpage, are much more limited in this area. But just about any web development tool, including the two above, will allow you to insert your own JavaScripts. And even though Dreamweaver can do a little JavaScripting on its own, you will probably find that it is somewhat less flexible in this regard than you might like.

Hey! I’m No Programmer

You don’t have to be a programmer to effectively use JavaScript in your web development projects. You just have to understand a few basic principles of web page layout and design. If you understand even the simplest rudiments of HTML, you will be able to insert working JavaScripts into your webpages successfully.

Using vs. Creating

Using JavaScript is a far cry from writing JavaScript. Not only does it require much less work, it also means you won’t have to spend the next six months reading up on how to write code. Why won’t you need to learn how to write your own JavaScript? Because there are dozens of places on the Internet were you can get other people’s code, legally and for free.

Going to the Source

One of the best sites on the Internet that I have found for this type of thing is the JavaScript Source (http://javascript.internet.com). This site will provide you with, all in one place, over six hundred working JavaScripts that you can use on your website for free. And it also provides detailed instructions on how to do so. Although the JavaScripts are broken down by category (navigation, buttons, passwords, &c.), you can also search by keyword, or browse the list of offerings in its entirety. And because they’re adding new ones all the time, remember to check back regularly. There’s even a button you can click to see the ‘Ten Newest Scripts’.

The Mechanics

Here comes the easy part. Once you have found a JavaScript you want to use, your next step is to retrieve it and plug it into your own webpage. The JavaScript Source allows you to either copy and paste right off the screen, or you can type in your e-mail address and have the JavaScript e-mailed to you. I usually go with the latter.

Webpages, at the HTML level, have basically two components, a head and a body. These will be separated from one another by the standard tags shown here:

<html>

<head>

</head>

<body>

</body>

</html>

What you see above is the most basic of webpages. You should be able to see in this example the discrete constituent parts of a webpage. The <head> tag, for instance, means that the head is beginning. And the next tag, </head> means that the head is ending. What we have above, in English, is this: HTML is beginning, the head is beginning, the head is ending, the body is beginning, the body is ending, and finally, the HTML is ending.

If you are working in Frontpage, Dreamweaver, or some other web developmental program that allows you to see the HTML, you will be able to see that these tags are spread throughout most pages, from top to bottom, in the order above.

JavaScripts are often written in such a way that part of the JavaScript goes into the head of the page, and another part goes into the body (what goes where will almost always be identified in the comments of the code itself). If you want to use a JavaScript written by someone else, all you need to do is cut and paste the appropriate parts into the right places, that is, into the head and into the body. The following JavaScript will create a small combo-box that lists Yahoo, Metacrawler, and Alta Vista. Users will be prompted to select one of these options and then press a GO button. Once they have done that, they will be taken to the appropriate location. This little JavaScript is especially useful for pages that are too full of information to allow for a long list of links. By using this JavaScript, all the links can be hidden within one small combo-box. Let’s take a look at how it works:

<html>

<head>

<script language="JavaScript">

<!-- Begin

function formHandler(form){var URL = document.form.site.options[document.form.site.selectedIndex].value;

window.location.href = URL;

}

// End -->

</script>

</head>

<body>

<center>

<form name="form">

<select name="site" size=1>

<option value="">Go to....

<option value="http://www.yahoo.com">Yahoo

<option value="http://www.metacrawler.com"> Metacrawler

<option value="http://www.altavista.digital.com"> Altavista

</select>

<input type=button value="Go!" onClick="javascript:formHandler(this)">

</form>

</center>

</body>

</html>

Notice all that the regular signposts are in this document: the html, the head, and the body tags. Don’t worry about the nuts and bolts of the JavaScript. It can take care of itself, as long as you’ve put it in the right places. One new tag you may notice is the script tag. This tags lets the browser know that what follows is actual JavaScript code. What you see further down in the body, is a bit of code that will call on the JavaScript in the head. That’s all there is to it.

Get to it!

All you really need to remember if you want to use JavaScript in your own webpages is where to get it and how to plug it in. That means finding somewhere that offers free JavaScripts (like the JavaScript Source) and remembering the distinction between the head and the body. Now you’re ready to start experimenting. Good luck!


Scott McLaren is a reference librarian at York University and an adjunct professor at the Faculty of Information Studies, University of Toronto. He has recently accepted an appointment as TEL Librarian at York and also serves as the Chair of their Information Technology Training Committee. As a Network Consultant in the private sector, he developed expertise in all versions of Windows, Novell's network operating systems, WinFrame, and Microsoft BackOffice. Projects have included the design, implementation and support of networks for organizations ranging in size from 3 to 900 employees in Toronto, Calgary and Vancouver. Recently published articles include "TEL: Something Old, Something New" and "Linux: a viable alternative or desert mirage?"


Copyright © 2000 Special Libraries Association - Toronto Chapter.  All rights reserved.