For example
- I have a dropdown box that gets a town from the table
- I want a textbox below it to find the county when a town is selected.
It will look this up from a table
e.g the table will look like this so using the townID it should be able to find the county.
TownID || Town || County ||
Thanks
Here is a very simple example using the DEPT table: demo page.
When you select a DEPTNO from the list, the associated DNAME value is displayed in the text field. This is done using an “advanced” dynamic action defined like this:
The “True Action” is defined like this:
This works by performing an AJAX round-trip to run the select statement. Note that we need to tell Apex to submit the current value of the P25_DEPTNO field so that it gets the right data back.
UPDATE
Of course, when possible it is best to avoid using AJAX as each action involves a round-trip to the server. In this case it could be avoided by getting all the required data into the select list return value and then parsing it on the client. To do that you could define the select list LOV like this:
Then use a dynamic action that uses Javascript expressions to parse the return value and populate the other items:
Of course, the select list no longer returns (just) the DEPTNO value, so I also need to parse that out into a separate field if I need the value (which I probably do). That requires a second True Action in the dynamic action definition.
The result (see new demo) uses no AJAX so is more efficient, but somewhat more complex to code – you need to know a little Javascript. Also you may need to handle the case where one of the data values includes your chosen delimiter (the colon in my example).
Which way to go depends on your particular circumstances: if the related data is expensive to obtain (e.g. uses a complex function call) it may be better to use the AJAX method and only get the data if really needed; but if it is inexpensive to get it up-front, the saving in round-trips may be worth while.