Free Book Excerpt -- Lotus Notes and Domino 6 Development

Chapter 16: Writing JavaScript for Domino Applications

Chapter 16: Writing JavaScript for Domino Applications

By Deborah Penny

[Note: Due to the length of Chapter 16 (70+ pages), we are including sections on Functions and Objects to illustrate its content. Chapter 16 covers JavaScript fundamentals, and is followed by Chapter 17, Real World JavaScript Examples, which has many chunks of code, including 20 useful utilities. Utility 5, validateDate() is included at the end of this document.]

In this chapter

  • What Is JavaScript?

  • JavaScript Is Not Java

  • JavaScript and the Domino IDE

  • The Document Object Model

  • JavaScript Support in Domino 6

  • When to Use JavaScript

  • A Look at JavaScript in Domino

  • JavaScript Libraries in Domino

  • JavaScript Principles 101

  • Syntax and Command Blocks

  • Statements

  • Output

  • Functions

  • Input Validation

  • Calculations

  • JavaScript Application

With the explosion of the World Wide Web in recent years, Web applications have become more interactive and users have become more demanding. This is quite different from the text-based newsgroups and FTP sites first served up by educational institution mainframes years ago. Technology and the Internet have certainly come a long way in two decades. With the onset of the Internet, several new programming languages came about, with JavaScript being one of them. Today JavaScript has not only become a frequently used buzzword by Internet-savvy users, but it also is now a scripting must among Internet developers. JavaScript is definitely a great asset to Web development and is now even more entwined in the Integrated Development Environment (IDE) in Domino 6.

This chapter gives you some background on JavaScript, details on its integration into Domino, and gets you started with JavaScript programming basics. Chapter 17, "Real-World JavaScript Examples," provides some great examples on real uses for JavaScript in Domino. Let's get started.


Functions are similar to methods but are not adjoined to a given base object. They offer the ability for programmers to group together many lines of code, or code blocks, to perform specific tasks so that they can be used repeatedly throughout the program. JavaScript already has some built-in functions, such as eval(), parseInt(), and parseFloat(), that you may already be familiar with. In many cases, however, programmers need to also define their own functions to supplement the built-in JavaScript functions. JavaScript offers this capability and flexibility.

Defining Functions

A function is declared by name and is invoked by calling its name in code. It is used in a block statement by using the reserved word function:

function functionname(parameter, arguments) { 
command block 

Function-naming conventions follow the same rules as variables:

  • Are case sensitive

  • Can include underscores

  • Must begin with a letter

The list of arguments passed to a function is separated by a comma and is always enclosed in parentheses. To execute a function, it must be called. Just defining it does not mean that it will be executed.


Parameters are used to pass data into a function and are used to return data from a function. Some functions return a value, whereas others just perform a task. In the following example, the statusbar() function uses the message parameter to pass data into the function:

function statusbar(message) {
   window.status = message;
   return true;
function statusbaroff() {
   window.status = "";
   return true;

The function is then called in the onFocus event of a field on a form:

statusbar("Enter the company name for this customer.");

When a user places the cursor in a field, the message is passed as the argument and is then displayed on the user's status bar. Figure 16.15 shows how the code looks from inside the JS Header:

Figure 16.15
The statusbar function inside the JS Header event.

Figure 16.16 shows the JavaScript calling the function in the onFocus event of a field.

Figure 16.16
The statusbar function inside a field's onFocus event.

Another way to pass arguments to a function is to set a global variable:

var favcolor = prompt("What is your favorite color?", "Blue");
function printcolor(favcolor) {
document.write("<HR>Your favorite color is <B><I>");

Here's how to call the function in an event:


Page 2 | Page 3




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...