Linking to a JavaScript Function

How to:

You can use a StyleSheet to define a link to a JavaScript function from any report component. After you have defined the link, you can select the report component to execute the JavaScript function.

Just as with drill-down links to procedures and URLs, you can specify optional parameters that allow values of a report component to be passed to the JavaScript function. The function will use the passed value to dynamically determine the results that are returned to the browser. For details, see Creating Parameters.

Note:

Syntax: How to Link to a JavaScript Function

TYPE=type, [subtype], JAVASCRIPT=function[(parameters ...)], $

where:

type
Identifies the report component that you select in the web browser to execute the link. The TYPE attribute and its value must appear at the beginning of the declaration.
subtype
Are any additional attributes, such as COLUMN, LINE, or ITEM, that are needed to identify the report component that you are formatting. See Identifying a Report Component in a WebFOCUS StyleSheet for details.
function
Identifies the JavaScript function to run when you select the report component.

The maximum length of a JAVASCRIPT=function argument, including any associated parameters, is 2400 characters and can span more than one line. If you split a single argument across a line, you need to use the \ character at the end of the first line, as continuation syntax. If you split an argument at a point where a space is required as a delimiter, the space must be before the \ character or be the first character on the next line. The \ character does not act as the delimiter.

In this example,

JAVASCRIPT=myfunc(COUNTRY \
CAR MODEL 'ABC'),$

the argument correctly spans two lines.

Note:

  • You can use the Dialogue Manager -HTMLFORM command to embed the report into an HTML document in which the function is defined.
  • When you have an HTML document called by -HTMLFORM, ensure that the file extension is .HTM (not .HTML).

For more information about the -HTMLFORM command, see the TIBCO WebFOCUS® Developing Reporting Applications manual.

parameters
Values that are passed to the JavaScript function. For details, see Creating Parameters.

Example: Linking to a JavaScript Function

The following displays the report and StyleSheet syntax used to link to a JavaScript function. It also shows the JavaScript function that is executed, and the result that is displayed in the browser.

The report request (which contains the inline StyleSheet) is:

TABLE FILE GGORDER
SUM PRODUCT_ID
BY STORE_CODE
BY PRODUCT_DESCRIPTION NOPRINT
IF STORE_CODE EQ 'R1250'
ON TABLE HOLD AS JAVATEMP FORMAT HTMTABLE
ON TABLE SET PAGE-NUM OFF
ON TABLE SET STYLE *
TYPE=REPORT, GRID=OFF, $
TYPE=DATA, COLUMN=PRODUCT_ID, JAVASCRIPT=showitem(PRODUCT),$
ENDSTYLE
END
-RUN
-HTMLFORM JAVAFORM

The JAVAFORM.HTM file that contains the JavaScript function is:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
// This function will display the value in the text box
function showitem(string) {
document.form1.text1.value = string;
}
// End the hiding here
</SCRIPT>
</HEAD>
<BODY>
!IBI.FIL.JAVATEMP;
<HR>
<B>Product Description:</B>
<FORM NAME="form1">
<INPUT TYPE="text" NAME="text1" SIZE="16"> </FORM>
</BODY>
</HTML>

When you execute the report procedure, the following report displays in the web browser. If you select a Product Code link, the JavaScript function ShowItem executes, and displays the value of the PRODUCT_DESCRIPTION field (a NOPRINT field) in the text box in the form below the report. For example, if you select the Product Code G104, "Thermos" displays in the Product Description field.