A check box is typically used to indicate whether an option should be turned on/off or is true/false.
The exercise in this section uses an if...else control structure. JavaScript Control Structures goes into more detail on control structure syntax and usage.
The exercise in this section assumes that you have previously inserted a new Dashboard section in Sample3.bqy and renamed the new section Controls. If you have been following the tutorial in sequence, you might try to associate a script to a check box on your own. The steps in the following procedure are very similar to the steps in the previous sections. |
To add a check box to the Controls section:
Elements pane, drag a check box control to the Content pane.
Use the Properties dialog box to change the Name and Title properties as follows:
Name—chk_IntervalValues
Title—Show/Hide Dollars
The Name chk_IntervalValues is used in the script for the Show/Hide Dollars check box.
Note: | The rest of this exercise associates a script with the check box. The script turns on or off the display of revenue values (the ShowIntervalValues property) of the RevByTime chart. |
Consider that a check box has two conditions: checked and unchecked (or cleared). Hence, the JavaScript needs to perform an action when a given condition is true and negate that action if it is false. “If” a condition exists, then a given action occurs; “else” the reverse happens.
To associate the ShowIntervalValues property with the check box:
With the Show/Hide Dollars check box object’s selection handles visible, select Dashboard, then Scripts.
Type the following into the Script Editor:
The parentheses enclose a statement that tests the checked property of the check box (chk_IntervalValues).
The first set of curly brackets, after the if, encloses the statement to execute if the test is true.
The second set of curly brackets, after the else, encloses the statement to execute if the test is not true.
Click in the parentheses after if, navigate to Controls Objects, then chk_IntervalValues, then Properties and then double-click Checked.
if (chk_IntervalValues.Checked)
if (chk_IntervalValues.Checked==true)
Click on the line between the curly brackets and add the statement to execute if the test is true.
Use the Object browser to navigate to Application, then ActiveDocument, then Sections, then RevByTime, then ValuesAxis, then Properties, and then double-click ShowIntervalValues.
You can see more of the object model by dragging the striped arrow at the bottom of the Object browser’s scroll bar.
Type =true and a semicolon (;) at the end of the line in the Scripting frame.
Click on the line between the curly brackets (after else) and add the statement to execute if the test is false.
Toggle to Run mode, press Ctrl+D, and test how the check box works.
You have just learned to associate a script with a check box.
Create another check box. Associate the check box with a script that shows/hides another property of the chart.
Any property in the Property dialog (in the chart section) can be accessed through the object model and JavaScript. To view the RevByTime chart properties, activate this section by clicking the title in the Sections frame, click in white space close to the chart, right-click, and then select Properties from the menu that is displayed.
You can also try the exercise on some other Interactive Reporting document file.