Executing it all dynamically with an AJAX callback
Rather than requiring the user to click a button to select a company and pass their CustomerID to the getDataForChart function, we will use an AJAX callback to call do this from the Spin List control.
Observe as the instructor defines the callback.
- In the left-side pane, click Controls.
- Click the customerIDHolderBox control.
- Add a new Action, an Ajax Callback.
- For Function name, enter passThisCustomerIDin.
- Click the Create function prototype hyperlink. This will generate a lot of well-written code we can take advantage of.
- Click .
- Click .
- Enter the comment Pass the selected CustomerID to the SQL statements.
- Save the onChange Event.
- Now we will write the callback. In the left-side pane, click Xbasic functions.
- The Xbasic Functions script window appears. Paste in all the code you copied.
- On line 4 (which is open), enter (on one line):
passThisCustomerIDin = getDataForChart(e.dataSubmitted.customerIDHolderBox)
The e object describes the current UX Component. It contains everything about the UX Component, including the data a user may enter or select. One of its properties is dataSubmitted, which can refer to a table field, or to some other control value, as we did here.
Remember that when we first started writing the function we set up the getDataForChart function to receive the selected customer’s CustomerID field value as an input parameter and then used it as an argument for the SQL statements.
Now you define the callback.
Touching up the interface
- Hide the customerIDHolderBox and Button controls.
- Make the width of the letterSlider and companyNameSpin controls 100%.