Official Content

Uses the controls “Click” and “OnChange” events to trigger JavaScript code.

Syntax

Control.JSEvent('Event_JavaScript', "Your_JavaScript_code")

Where:
Event_JavaScript’
    Is the name of the JavaScript event to be dealt.

"Your_JavaScript_code"
    code to be dealt.

Scope

Objects: Transaction, Web Panel
Controls: Bitmap Type Variable, Button, Combo, Dynamic Combo, Dynamic List Box, List Box, Picture, Text Block
Generators: .NET, Java, Ruby (up to GeneXus X Evolution 3)

Description

The valid values are: "onclick" (Edit, Button, Pictures, Bitmap type variables and Text Blocks type controls) and "onchange" (for Combo, Dynamic Combo, Listbox and Dynamic Listbox type controls).

It must be possible to include the JavaScript code written in the second parameter in an IF; i.e.: it must return TRUE or FALSE.
If the result is TRUE, the control associated event will be triggered. 

Samples

ButtonName.JSEvent( 'onclick', "confirm( 'Are you sure?')")

When the user presses the button, the confirmation will appear and, only if the answer is Yes, the GeneXus event associated to the button will be executed (if any). 

Compatibility

Warning: Since GeneXus 15 it is recommended to use whenever possible External Objects for Javascript instead of the JSEvent event. The JSevent use cases are still valid to trigger a function based on user confirmation (such as the javascript confirm function).

Since GeneXus 16 upgrade 5, it is neccesary to modify Javascript code for complex conditionals. If you have conditional similar to:

ButtonControlName.JSEvent("onclick", !"if (/*conditions*/) {confirm('Something');} else {true;}")

you need to change it in the following way adding an anonymous wrapper function and make sure to always return a True or False value:

ButtonControlName.JSEvent("onclick", !"function() {if (/*conditions*/) { return confirm('Something');} else { return true;} }()")

otherwise the following error will appear on the javascript console

SyntaxError: Unexpected token 'if'
    at new Function (<anonymous>)

See Also

Selecting Events


Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant