Let's assume you have an Order Management application with an Order Placement form. You need to display a coupon code which the customer can use to get a discount on the next order. For this you can write a script for on success form event. This script will run on successful submission of the Order Placement form. In this case, when the customer successfully places the order, a unique code is displayed.