Difference between revisions of "Dependent dropdowns"
| Line 22: | Line 22: | ||
When a web server gets a request to serve a page it will first parse all server side code (HTMPL) and replace that code with valid HTML code before passing that HTML back to the requester of the page. | When a web server gets a request to serve a page it will first parse all server side code (HTMPL) and replace that code with valid HTML code before passing that HTML back to the requester of the page. | ||
| + | To start, you will want to have a place in the database where you store the values of the drowndowns and their dependencies. | ||
| + | This can be done in many different ways (having 3 custom tables, then using 2 more to store the LREL between them), but let's keep it simple for now: as you may know, the request area structure is much like denpendent dropdowns: once you select a node in the tree, you get access to the underlying nodes. | ||
| + | |||
| + | <small>As a sidenote, you could simply use one field similar to the request area to implement this functionality instead of using all dropdown fields. But in case you still want to go ahead with the dropdowns, read on...</small> | ||
== All together now == | == All together now == | ||
Revision as of 09:58, 24 March 2009
Introduction
On a regular basis, people ask on the forums for a solution implementing dependent dropdowns.
- dependent dropdowns
- values in a dropdown are depending on a selection made in an earlier dropdown field.
Since selecting a value in a dropdown is done client-side, at least some part of the solution will include (client-side) javascript coding.
Possible solutions may exist out of these:
- use hidden frames to call a custom made HTMPL file containing the values for the next dropdown, then use this data to populate the dropdown in the main window
- an AJAX implementation
- find a way to call the CA Service Desk web services using javascript, get the necessary values from the server and populate the dropdown
- pre-load all data when your form gets loaded, then use javascript to display values when making selections in the dropdowns
All these solutions will have advantages and disadvantages (e.g. calling webservices, using AJAX and even the 'hidden frame solution' may work a little slower compared to pre-loading all data. On the other hand, pre-loading data may take a long time if you have hundreds of values)
Let's take a look at an implementation that pre-loads all data.
Components
When a web server gets a request to serve a page it will first parse all server side code (HTMPL) and replace that code with valid HTML code before passing that HTML back to the requester of the page.
To start, you will want to have a place in the database where you store the values of the drowndowns and their dependencies. This can be done in many different ways (having 3 custom tables, then using 2 more to store the LREL between them), but let's keep it simple for now: as you may know, the request area structure is much like denpendent dropdowns: once you select a node in the tree, you get access to the underlying nodes.
As a sidenote, you could simply use one field similar to the request area to implement this functionality instead of using all dropdown fields. But in case you still want to go ahead with the dropdowns, read on...