Search these areas:
Help
Support Forums
Product Info



Introduction
DataWeb: What's New
Creating an Application
The DataWeb Designer
Application Management
Data Tables
Data Tables
Views
View Basics
Converting HTML Pages to Views
Incorporating Script in a View
-HotRAD Substitution Syntax
-Calling Functions
-The Record Object
View Property Reference
View XML Reference
URL Parameters Reference
SQL Expression Reference
Templates
Components
Data Analysis
Members
Security
Importing
Exporting
FTP
JavaScript
Object Model
Full-Text Search
Domain and Email Hosting
HotBlock Modules
Account Management
Glossary
New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

DataWeb User's Guide

Calling Functions
If you want to call a function from your view, it's best to write functions in a script class, import the class from the view, and call these functions as methods on the class, rather than including the function definition in the view. This way you can take advantage of the syntax checking that the scripting environment provides. When you check the syntax of a view, the DataWeb Engine checks only the XHTML in the view; it doesn't check the syntax of any script included in that XHTML. Also, some elements that you might include in a script can conflict with XHTML elements. Putting functions in a script class can help you to avoid confusing XHTML syntax errors.

A script class can be imported by any view that has the necessary permissions. Once the class has been imported, script running in the view can call its methods. For example, suppose you have defined the following function in a class called DateUtilities.ws:

function dateFunction()
{
   // Get the current date, and create a date string
   var myDate = new Date();
   var theDay = Date.getDate();
   var theMonth = Date.getMonth() + 1;
   var theYear = Date.getYear();
   return (theMonth + "/" + theDay + "/" + theYear);
}
To call this function from a view, use DataWeb substitution syntax within the view's source code. Call the import() method of the Classes object, assign the object returned to a variable, and use this variable to call the dateFunction() method of the class:

#var c = classes.import("/DateUtilities.ws"); c.dateFunction()#

You can also call a method that takes arguments from within the view's source code, as follows:

#var c = classes.import("/SomeClass.ws"); c.myFunction(arg1, arg2)#


Related Topics

Classes Object

Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
Email Us