It is common to use HTML buttons to perform calculations on-demand or to present additional information. For example, rather than display customer notes that take up space in a report or that users view infrequently, you can create an HTML button that, when clicked, displays the information when users want to view the information.
These types of event handlers typically require access to data in the report, such as row data, aggregate data, or report parameter values. To provide event handlers with access to report data, you must do the following:
After you create a variable, use dataObject to access the variable in an event handler. For example, to access the variable CustomerNotes, use dataObject.CustomerNotes, as shown in the following event handler code:
The next example shows how to use an HTML button to calculate the price of a product after applying a discount specified by the user at report view time.
Figure 22-8 shows the report in the web viewer. The report lists the products and their MSRP (Manufacturer’s Suggested Retail Price). Each product row contains a Discounted Price button for calculating the discounted price for that product.
To create this HTML button, a button labeled Discounted Price is inserted in the detail row of a table. The HTML button’s event handler code requires the MSRP values to calculate the discounted price, so a variable is created.
Figure 22-11 shows the definition of a variable named Price.
The first line after the opening brace prompts the user for a discount value and stores the value in the Discount variable. The second line calculates the discounted price using the values in the Price and Discount variables. The third line displays the results in a message box. Note that this event handler code covers only the main tasks. A more complete event handler would also perform data validation to ensure that the input value is a number, and handle the case if the user chooses Cancel at the prompt.