onsubmit event



The onsubmit event runs client-side code before a response is submitted to a Profound UI Rich Display File screen or a Genie screen.  This typically occurs when a function key is pressed or a button/hyperlink is clicked.  If the expression evaluates to false, the response is not submitted.

Examples:

In the following examples the JavaScript function validateNewsletterSettings() is used to validate user input when a screen is submitted.

The function can be placed into an external JavaScript file:

function validateNewsletterSettings() { if (getObj("NEWSLETTER").checked && get("EMAIL") == "") { // if newsletter checkbox is checked and email address is blank alert("You selected the checkbox to receive the weekly newsletter. Please provide an email address."); // show message to user getObj("EMAIL").focus(); // focus cursor onto the email field return false; // validation check failed; prevent the screen from submitting by returning false } return true; // validation check passed }

Then, the following can be placed onto the onsubmit event:

validateNewsletterSettings();

Alternatively, if you wanted to avoid using an external JavaScript file, both the function and the call to the function can be be placed onto the onsubmit event, as follows:

function validateNewsletterSettings() { if (getObj("NEWSLETTER").checked && get("EMAIL") == "") { // if newsletter checkbox is checked and email address is blank alert("You selected the checkbox to receive the weekly newsletter. Please provide an email address."); // show message to user getObj("EMAIL").focus(); // focus cursor onto the email field return false; // validation check failed; prevent the screen from submitting by returning false } return true; // validation check passed } validateNewsletterSettings();

For Genie, a variable named 'key' is available on the event.  This can be used to determine which key was pressed.

Example:

The variable 'key' is a JavaScript string that will contain one of the following values:

  • "SYSRQ" if the system request key was pressed.

  • "ATTN" if the attention key was pressed.

  • "ERRORHELP" if the help key was pressed while a message was displayed in the error line.

  • an AID code if any other key was pressed.

For Rich Displays, the event can be specified as a function name only. If used in this way, a response object containing all the values is passed to the specified function. The function can interrogate and even change the response values. For RPG Open Accesss programs, the names in the object are stored as "FORMAT.FIELDNAME", where the format and the field name are capitalized.

Example:

Your function can be declared in an external file as follows:

The onsubmit event would only contain the name of the function name: