JavaScript enables on-the-fly calculations to be scripted for use in Notes as well as on the Web. If you have an application that will be used in both Notes and the Web, JavaScript allows you to code one solution for both. Here's how.
This example takes you through some simple math. The first thing you have to keep in mind is that all fields in JavaScript are evaluated literally. If the number field format is set to currency, the currency sign will be included in the calculation and will result in a NaN. In this example, a calccosts () function has been created in the JS Header on the problem report form in the sample database. Here's the code:
function calccosts() { myform = document.forms[0]; var result = eval(myform.Hours.value * myform.Rate.value); myform.TotalCost.value = result; }
This function multiplies the two fields Hours and Rate on the form and sets the var result with the result. The TotalCost field is then set with the value of the var result . The Hours, Rate, and TotalCost field formats are all set to a number, decimal, or varying data type on the form.
To call the function, place the calccosts() statement in the onBlur event of the Hours and Rate fields. When either field is exited, the calccosts() function is called. Figure 16.20 shows how it looks in Domino Designer.
Figure 16.20. Calling the calccosts() function in Domino Designer.
Figure 16.21 shows how the result looks on the Web.
Figure 16.21. The calculation code results on the Web.
Figure 16.22 shows how the same result looks in Notes.
Figure 16.22. The calculation code results in Notes.
The differences are only in the client ”the JavaScript code works the same in both.
Part I. Introduction to Release 6
Whats New in Release 6?
The Release 6 Object Store
The Integrated Development Environment
Part II. Foundations of Application Design
Forms Design
Advanced Form Design
Designing Views
Using Shared Resources in Domino Applications
Using the Page Designer
Creating Outlines
Adding Framesets to Domino Applications
Automating Your Application with Agents
Part III. Programming Domino Applications
Using the Formula Language
Real-World Examples Using the Formula Language
Writing LotusScript for Domino Applications
Real-World LotusScript Examples
Writing JavaScript for Domino Applications
Real-World JavaScript Examples
Writing Java for Domino Applications
Real-World Java Examples
Enhancing Domino Applications for the Web
Part IV. Advanced Design Topics
Accessing Data with XML
Accessing Data with DECS and DCRs
Security and Domino Applications
Creating Workflow Applications
Analyzing Domino Applications
Part V. Appendices
Appendix A. HTML Reference
Appendix B. Domino URL Reference