|WebBlocks, Execution Script
The use of these functionalities requires a minimum amount of basic programming knowledge. If you are only slightly familiar with programming techniques, our
technical support team will do their best to help you. However, if you are not at all familiar with these practices or have never used programming techniques,
your website (the reflection of your know-how) is not the ideal place to start out. You can refer to one of our Internet Solution Centers who will help you
with the global achievement of your project.
The execution script associated to the WebBlock allows you to define the VBScript code that will be executed when submitting the form. You can use basic
operations in VBScript language, such as:|
- Mathematical calculation operations (+, -, *, etc.).
- Character string concatenation operations.
- Basic VBScript functions, such as Len(), Trim(), etc.
- Algorithms (conditional statements), such as If/Else/End If, etc.
IMPORTANT: In order for the code to be executed when the form is submitted, you must use a "Submit and execute the calculation script" type submit
Also note that you cannot carry out operations on Date/Time controls (retrieve their values, define their values, etc.).
To manipulate the values associated to the controls in your form, you have two functions at your disposition: GetItemValue() and SetItemValue()
General remark: Control names are not case sensitive and they correspond to the names specified in the property editing pages.
| Function GetItemValue( ByVal strItemName )|
This function returns the current value associated to a control or an element.
strItemName: The name of the control containing the value that must be returned.
This function is compatible with all of the form elements. If the control is a drop-down list (Combo), the return value will be the value of the selected
element. If the control is a check box, the associated value will be returned (1 if the value is not specified) if the box is checked.
| Sub SetItemValue( ByVal strItemName, ByVal varValue )|
This procedure allows you to modify the value of a given control.
strItemName: The name of the control containing the value that must be modified.
varValue: The new value associated to the control.
Because this function is a VBScript Sub procedure (no return value), it needs to use the "Call" prefix to get a return value.
This procedure is compatible with all of the form elements. If the control is a drop-down list (Combo), the selected value will correspond to the value set
in the parameters if it is found in the list. If the control is a check box, the box will be checked if the set value is a number other than zero.
| Simple Example|
Let's suppose that a form contains 3 "Form - Text Zone" elements named "A", "B", and "C".|
The user will enter numeric values in "A" and "B" and the following script will assign the results of the calculation A + B in zone C:
nResult = GetItemValue("A") + GetItemValue("B")
Call SetItemValue( "C", nResult )
Note the use of the "Call" prefix when calling the SetItemValue() procedure.
| Evolution of the example using a Drop-Down List|
Take the previous example and add a drop-down list in your WebBlock to choose the calculation operator. Name this list "Operator" and use the following
Then use the following code for the execution script:
Dim nOperator, nValue1, nValue2, nResult
nOperator = GetItemValue("Operator")
nValue1 = GetItemValue("A")
nValue2 = GetItemValue("B")
If ( nOperator = 2 ) Then
nResult = nValue1 - nValue2
ElseIf ( nOperator = 3 ) Then
nResult = nValue1 * nValue2
ElseIf ( nOperator = 4 ) Then
nResult = nValue1 / nValue2
nResult = nValue1 + nValue2
Call SetItemValue( "C", nResult )
| Evolution of the example using a Text element|
The text element (not to be confused with the "Form - Text Zone" element) remains invisible if no text is entered in its properties. You can assign a name to
this element in the same way as a form element. If a navigation behavior is associated to the element, it will not be visible or useable unless a text is assigned
to the element.|
Take the WebBlock from the previous example and add a Text element that you will name "Results". Do not assign text to this element (leave the entry zone
Next, modify the code of the execution script and add the following line at the end of the code:
Call SetItemValue( "Results", nResult )
Run this WebBlock again. You will notice that the calculation results are displayed in Text Zone "C" and also in your Text element!
| With a little imagination!|
Let's suppose that you sell radiators and that the different models (6) that will be proposed depends on the results of a calculation function concerning the
surface area of the room, the height of the room, the insulation level, and the climate.
In your form, after a bit of explanatory text, you will put:
- 2 "Form - Text Zone" elements to enter the surface area and height of the room (feel free to limit the entries, for example:
surface area between 10 and 70 sq ft, height between 6 and 9 feet).
- 2 "Form - Drop-Down List" elements to select an insulation type ("Excellent/Average/Poor") and a Region (Mountain/Temperate/Sunny).
Create 6 text elements (named Radiator1 - - - Radiator6) in a cell and leave the text blank. For your navigation behavior, you are going to select "Open the
Shopping Cart (Shop) component", "Propose a specific element", "Radiator 1" (then Radiator 2 for the second text zone, and so on and so forth). Because
these zones are blank, nothing will be displayed.
Now insert a "Submit and execute the calculation script" submit button.
Initially, with your explanatory text, the WebBlock will display the blank entry zones, the choice lists, and the submit button that you have named "Which
radiator is best for you?".
When the user has entered their values, made their selections in the drop-down lists, and pressed the submit button, you will carry out a calculation
operation which will result in the proposition of the corresponding radiator with sufficient capacity to heat the room.
If the suitable appliance is Radiator1, you will use Call SetItemValue( "Radiator1", "We recommend our type 1 radiator, click here"), and so on and so forth
for the other results.
As you have already associated the correct navigation behavior to the "Radiator1" text element, which was formerly invisible, the visitor will be directly
taken to the page allowing them to purchase a radiator that corresponds to their exact needs!
| Several important recommendations for forms that use execution scripts|
1) Don't use the same name for multiple controls.|
2) Use simple and indicative control names.
3) Set up a validation for the fields in your file that is as strict as possible in order to limit the risk of script error.
4) Systematically test your script after each modification.
5) Do not run tests with "your values". Put yourself in the place of the user, who might enter any possible values.
6) Build your script little by little and test it in the various stages of its development. This will allow you to detect possible errors much more
7) If you encounter an error when executing the script and you can't find the cause, backtrack through your development and apply comments to the lines in
your code. To do this, start the line with a simple quotation mark.
Another more advanced technique is to add a Text element (that you can name "Debug, for example) to your form. Assign a progress indicator to the element
throughout the execution of the script, like this:
Call SetItemValue( "Debug", Stage 1" )
Call SetItemValue( "Debug", "Stage 2" )
The displayed value will indicate the stage after which your script was interrupted.