Sanbachs.com
Serving the DataPerfect* Community

Home > Firestorm > Project List > JavaScript Support
Last updated: June 21, 2001

Firestorm – JavaScript Support

We will use a very simple, one panel database. The fields will be:

P1F2
A user identifier, which will be a small number (GZZZZ9).
P1F2
A value identifier, which will be a short alphanumeric string (A30).
P1F3
A value, which will be a text field (A30A0).

The panel will be indexed with fields one and two, in that order. The idea is that a numeric identifier will be assigned to each "user" of this database. Each user can store as many name to value associations as they wish. Field two becomes a kind of key, used to retrieve an arbitrary value stored in field three.

The database itself can only be accessed on the web server, and JavaScript cannot do this directly. We have defined a simple CGI script to access the database and communicate with JavaScript.

Each time the script is run, it is passed the following CGI variables from a form that it presents.

ID
The numeric identifier of the user.
Key
The name of the value to be stored or retrieved.
Val
The value to be stored. This will be missing if a value is to be retrieved.
Action
The character 'G' if a value is to be retrieved, or 'P' if the value is to be stored.

To get things started, a user can run this script passing in only the ID number. The script will respond by not doing any database access, but merely presenting the form. Then database records can be created by typing a name into the first field, a value into the second field, the letter 'P' into the third field, and clicking on the button. A database value can be retrieved by typing its name into the first field, the letter 'G' into the third field, and clicking on the button.

So far, we have only a very simple (and ugly) form to use the database. But, this CGI script was not intended for human use. To integrate this with JavaScript, we need to use HTML frames. A JavaScript function in one frame will place values into the form fields (in a second frame), then cause the form to be submitted. Sometime later, after the CGI script has run on the server, the results will be available in the second frame. Now, a simple change to the JavaScript code produced by the CGI script allows communication with JavaScript code in the first frame.

There is a timing problem with web applications and JavaScript. If we have a JavaScript function that sets up the values in the form fields, then causes the form to submit, the results will not be available until after the CGI script has completed on the server and the browser has displayed the resulting HTML page. We use the "onLoad" attribute of the <BODY> tag to get around this. The adapted CGI script is just like the earlier one, except that in the "onLoad" attributes, instead of doing a JavaScript alert, it calls a function in the other frame. This solves the timing problem.

Frames have names. This code assumes that the first frame is named "db" and the second "fs". The callback functions are named "put-result", "get-result", and "err-result". The first of these expects one argument, a number error code for the result of the put operation (or zero if it succeeded). The second expects the value (field three) of the retrieved database record. The last expects a numeric error code for the get operation if it fails for some reason.

Now we are in a position to study the JavaScript code that is loaded into the "db" frame. This file is named db.html and you can study its source code by clicking on View Page Source in your browser.


Contacting Sanbachs

Sign or browse our guest book.

webmaster@sanbachs.com
A. Lewis Bastian, Jr.
Bruce Conrad
Thom Boyer

Disclaimer

*DataPerfect® is a copyright of Novell, Inc. Sanbachs.com is not affiliated with Novell, Inc.

visitors since June 21, 2001.
Copyright © 2000 Sanbachs.com