Using JavaScript to enhance forms and pages
As we have seen already, there are many ways in which JavaScript can be added into web applications. In this section, we explore some additional ways that scripts can be used to enhance forms and pages.
Run JavaScript on load
Not uncommonly, you may want to run some JavaScript when a form first loads into the browser. This can be a bit tricky since documents can open in Read or Edit mode, and in Edit mode documents are often refreshed from the server. You may want to run a script only with a document in Read mode or only in Edit mode. And you probably want an initialization script to run only once even if the document is refreshed from the server. These kinds of situations need to be addressed and tested carefully to assure a good final product.
There are some obvious places to insert JavaScript so that it runs when a form first loads:
The JS Header
The onLoad Event
Inline on the form
Positioned in any of these locations, a script might possibly run...