Skip to main content

IMPORTANT - Product End of Life Statement - IMPORTANT

Request RE, Survey, and Calendar 1.5 Support Ending December 31, 2020
Contact Kinetic Data Support with Questions
Kinetic Community

How to prevent page submission on error of a Submit event

When using custom events on the Submit action of a page, it is often advantageous to add a "catch all" for potential errors and to prevent the page from submitting. For example, if I have a custom event on Submit that copies multiple elements from the page and stores them in a hidden answer field, and that event errors, I don't want to page to submit (indicating to the user that the request was successful) with a blank answer field.


See example below.


To prevent the page from submitting when there is an error, the Custom Code can be wrapped in a Javascript try/catch block.  For example:

  try {
    /* Custom code goes here; for this example I am doing something that intentionally throws an error */
    var fu = bar;
  } catch(err) {
    /* In this case we want the error message to be displayed with some context in an alert popup */
    alert('There was a problem in the Raise Error Submit event: ' + err);
    /* Here is the magic word, by ensuring that we stop the action, further processing of the submit event chain halts */

will pop up a javascript alert with the contents "There was a problem in the Raise Error Submit event: ReferenceError: bar is not defined".







All that is strictly necessary to prevent page submission is to return false. An alert or display on the screen of some kind is helpful for the user to understand why they clicked submit and did not move forward.