Java Script (JScript)
Listed below are the questions that we are asked quite often. Before you write us, be sure to check here.

Programming

Programming

Adding a component to a web page, using the OBJECT tag

The syntax for adding a component to a web page is:
<OBJECT classid="clsid:CLASSIDENTIFIER" id="IDENTIFIER">
</OBJECT>

where 

  • the IDENTIFIER is the ID of the object being added. The ID attribute can be used by a JavaScript (via the HTML DOM) or by CSS to make changes or style the element with the specified id. The id attribute specifies a unique id for an HTML element
  • the CLASSIDENTIFIER is the object's class identifier as CD481F4D-2D25-4759-803F-752C568F53B7

The CLASSIDENTIFIER is unique for each /COM object, and can be found on control's documentation on the main object page, where something like follows is displaying, or explained here;

Tip The /COM object can be placed on a HTML page (with usage of the HTML object tag:  <object classid="clsid:...">)  using the class identifier: {CD481F4D-2D25-4759-803F-752C568F53B7}. The object's program identifier is: "Exontrol.G2antt". The /COM object module is: "ExG2antt.dll"

The following sample adds the eXG2antt component to a web page:

<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1">
</OBJECT>

 

Where I should initialize my control?

A) You can call the Init method during load event of the Body HTM element, like in the following sample:
<BODY onload='Init()'>
<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1" width="192" height="192">
</OBJECT>

<SCRIPT LANGUAGE="JScript">
function Init()
{
	G2antt1.Columns.Add("Task");
	G2antt1.Chart.FirstVisibleDate = "1/1/2001";
	var var_Items = G2antt1.Items;
	var_Items.AddBar(var_Items.AddItem("Task 1"),"Task","1/2/2001","1/4/2001",null,null);
}
</SCRIPT>
</BODY>

B) You can add a SCRIPT right after the </OBJECT> so the code is executed once the object is created as in the following sample:

<OBJECT classid="clsid:CD481F4D-2D25-4759-803F-752C568F53B7" id="G2antt1">
</OBJECT>

<SCRIPT LANGUAGE="JScript">
	G2antt1.Columns.Add("Task");
	G2antt1.Chart.FirstVisibleDate = "1/1/2001";
	var var_Items = G2antt1.Items;
	var_Items.AddBar(var_Items.AddItem("Task 1"),"Task","1/2/2001","1/4/2001",null,null);
</SCRIPT>

Handling Custom Events or Events with Parameters

The syntax for handling the events with parameters is:
<SCRIPT FOR="IDENTIFER" EVENT="EVENT(PARAMETERS)" LANGUAGE="JScript">
</SCRIPT>

where the IDENTIFIER is the ID of the object being handled, and the EVENT is the name of the event being handled. The PARAMETERS gets the list of parameters that the event carries.

Using the FOR and EVENT attributes to associate events gives you access to custom events fired by embedded objects and to any parameters that an event generates. Unlike standard events that can be bound using attributes or properties, in the case of custom objects these are not available.

Use the FOR attribute to specify which element or object to handle, assigning it an identifier or the name of an object, application, or control. If you don't specify this attribute, the handler is bound to the window by default. Notice that JScript is case-sensitive, so you must type the identifier or name exactly as it appears in the corresponding element or object.

Use the EVENT attribute to specify which event to associate to, assigning it an event name. If the event generates parameters (few predefined events do), you can also specify a list of comma-separated parameter names enclosed in parentheses immediately after the event name. The parameters are untyped. Because JScript is case-sensitive, make sure you always spell event names in lowercase letters. Also, if you give a parameter list, VBScript requires that all parameters defined for the event be listed, even if they are not used.

The following JScript example displays a message box when the user clicks an anchor element in the gantt control:

<SCRIPT FOR="G2antt1" EVENT="AnchorClick(AnchorID,Options)" LANGUAGE="JScript">
	alert(AnchorID);
</SCRIPT>

The sample handles the AnchorClick event of the eXG2antt component.

Event not fire during initialization

Initializes the control using the option A), as described on: Where I should initialize my control? ( using the load event of the BODY element ). 

Changing the parameters by reference do not work during events, such as KeyCode parameter of KeyDown(KeyCode,Shift) event

Some of the events pass the parameters by reference. Such of event could be the KeyDown event, where the KeyCode parameter is passed by reference, so user can change it runtime. 

For instance, the following JScript sample changes the TAB behavior, so if user presses the TAB, the control sends instead the RIGHT key, so it advance to the next editable field:

<SCRIPT FOR="G2antt1" EVENT="KeyDown(KeyCode,Shift)" LANGUAGE="JScript">
	if ( KeyCode = 9 )
		KeyCode = 39;
</SCRIPT>

In this code, the KeyCode = 39, won't have any effect so instead you have to use the EventParam property like shown in the following sample:

<SCRIPT FOR="G2antt1" EVENT="KeyDown(KeyCode,Shift)" LANGUAGE="JScript">
	if ( KeyCode = 9 )
		G2antt1.EventParam(0) = 39;
</SCRIPT>

or an equivalent sample:

<SCRIPT FOR="G2antt1" EVENT="KeyDown(KeyCode,Shift)" LANGUAGE="JScript">
	if ( KeyCode = 9 )
		G2antt1.Template = "EventParam(0) = 39";
</SCRIPT>

 The EventParam property is available for almost all of our components. The Template property specifies the x-script code to be executed at runtime.

How can I find the CLASSIDENTIFIER I should use to instantiate the control on a web page?

The class identifier can be found on the control's documentation. 

You can follow the steps to find the classid ( for instance, we are trying to get the classid for the exg2antt control ): 

Under the object's help you will find:

Tip The /COM object can be placed on a HTML page (with usage of the HTML object tag:  <object classid="clsid:...">)  using the class identifier: {CD481F4D-2D25-4759-803F-752C568F53B7}. The object's program identifier is: "Exontrol.G2antt". The /COM object module is: "ExG2antt.dll"

Copyright 1999-2017 Exontrol. All rights reserved.