Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Support Forum



populating a field with a set of lookup values based on another selection
husnasale asked:
I have three tables as follows:
1. states with field state: entries KAZA, BABA
2. stations with fields:station     state
                  Entry GAGA        KAZA
                  Entry WAWA        BABA
                  Entry DADA        KAZA
I have created a view with lookup fields p_state and p_staion.

I want a situation such that each time I select state value KAZA in the p_state field, only the station value GAGA and DADA appear in the p_station field

How can I do that with <ws: select tag.

Thank you
 
  Kevin_J_Nicholls (DataWeb) responded:
  To change the elements in one drop down box as a result of changing another drop down box value requires inserting custom client-side JavaScript appropriately into "source" tab of a view.

While the DataWeb platform fully supports custom client side JavaScript and HTML development, there are no tools offered to directly support this type of development. 

This type of development does require some amount of expertise the following, standard web technologies and some DataWeb technologies:
1) Standard HTML <select> and <option> objects
2) Client side JavaScript, (onchange events) and DOM selection techniques
3) DataWeb server side java script, looping, conditionals, record and result set objects.
4) Tricky: producing client side javascript as a result of server side scripting.
5) Incorporating all of these technologyies into views using the “source” tab of your veiw (<ws:htmlblock> and incorporating serverside scripting into views)
5) Possibly (if your station list is long and to make your solution scalable) using JSON, XMLHttpRequest Objects, and DataWeb script classes (with Webcall function).

If you don’t have expertise in these technologies and objects, DataWeb offers consulting services capable of writing this type of code for a fee.

For the below description, I’ll assume you have the expertise in the areas suggested above.

Some general approaches:
A) For best results, fully normalize you data. For example, don't put looksups to BOTH States and Stations on your “transaction” table.

A.1) Just one lookup to the lowest level of detail (in this case, Stations).  If you do use both, this gives the user the possibility of selecting DADA for a Station and BABA for a state (which is wrong). 

A.2)Make sure to have a lookup from the Stations table to the States table.  On reports and details views, you can now show the State by adding that value from "Insert -> Field" and clicking first on the lookup field to station, then the lookup field to state. You can also create display fields like "Station (State)" by using the magic wand next to "Display" and adding a formula like:
[State:Name] + "("+[State:Station:StationName]+ ")"


B) Back to your original question: the best approaches I have seen have been to

B.1) Create the States drop down from plain old html (standard html <select> tags and insert into <ws:htmlblock> blocks).

B.2) "Fill up" this states select box with <options> tags (states) using the DataWeb server-side JavaScript. Use the DataWeb resultset object, the while loop, and the response.write function to produce a string like ‘<option /><option value=”1”>KAZA</option><option value=”2”>BAZA</option> ... ’.  In the while loop, check the current value of the record.Station value to add ‘selected=”selected” to the correct option tag (if a station has already been selected.

B.3) Set the default filter in your Stations drop down (in the DataWeb Designer) to something like “StationId:StateID=#record[‘Station:StateID’]?record[‘Station:StateID’]:0#” .  If there is no value for station yet (like for a new record), the station drop down will show nothing.  If the station has already been selected, the drop down will be filtered with stations from the same state (with the current value of station selected).

B.4) Create another SERVERSIDE DataWeb script that creates a CLIENTSIDE JavaScript object of Station values;  The properties of the object will be a StateID, and the value for each of these IDs would be one string with a series of “<option />” tags (similar to states strings produced above). For example, for KAZA (I’ll assume RowId=1), object[1] = ‘<option value=”1”>GAGA</option><option value=”2”>DADA</option>’;

B.5) add an “onchange” JavaScript event to the States drop down that will replace the current options of the Stations stations drop down with the correct value of the object created in B.4 (uses client side DOM selection and properties);


Again, if these technologies and approaches mentioned are not familiar to you, DataWeb consulting services and produce the desired effect in just a few hours.

Does this explanation help?
 
  Please Log On
or create your own DataWeb Account.
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us