CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Dependant Listboxes

Print topic Send  topic

Author Message
Damian
Posted: 07/25/2004, 6:39 PM

Howdy again,

I have a search form with the following list boxes
[state]
[ditrict]
[town]

The list box values are pulled from the following tables
state (id,country,state)
district (id,state,ditrict)
town (id,district,town)

In state the value country is set oin the grid as a specific country.
In district the value state needs to be set based on the value set above (eg
if you select state 100 above, then all districts in State 100 will show).
In town the value district needs to be set based on the value set in
district (as above).

Once the user selects the Town and submits the search then ALL members from
that Town should be displayed.

My problem is getting the second and third listboxes to update their
contents - ie someone selects the state, the ditricts update, they selcet a
district and the towns update. When they hit Submit and a town has been
selected it will pass the town to the Search Results Grid.

Any ideas...


Walter Kempees
Posted: 07/26/2004, 5:29 AM

Solved.
Create your standard search form, meaning:
Search form should work as generated from standard, including changing the
search fields to listboxes.
Therefore you should be able to select a value from dropdown
state/district/town, and it should reflect the correct records in the result
grid.
A standard generated search forms will add the search parameters to the URL
this is what I will be using to preset the other list boxes.

Way to do it:
1: Set every listbox to submit the search form after a value is changed,
this will act as if someone selected a value from the listbox and press
[Search].
How: on the listbox, events, client side, On Change add action Submit
Form.
2: In the state listbox properties everything can stay as generated but in
the district list box's properties, data section, check the settings...
Data Source press the elipses (...) which will bring you to the Data
Source window, this can be Table or SQL Type depending on your initial
query.
Here you should make the SQL dependent on the first list box's value
(grin).
Your SQL should look something like SELECT id, district FROM district
WHERE state = {s_state) ORDER BY district
assuming that s_state is the name of your state listbox output.
In the parameter section (lower part of the Data Source window) you
should tell CCS what to substitue your parameter with.
Press the + sign add a variable, with the same name as in your SELECT,
s_state.
Parameter source is the value to be substtituted and can be seen in the
URL line of your browser but should be s_state as well
Set the datatype to the correct value (Integer) and the box next to in
to URL.
The rest you can figure out as needed, default value.
Apply this to the town list box as appropriate.

In the end you should have linked list boxes, with the advantage of being
able to select a value from the second box even when the first
is not set, it will then display all values.

Try this and come back.
Additional possibilities are to display only the states, districts and towns
that are actually in the database (as opposed to values from the reference
tables)
thereby helping the user to not search for values that are not in the
database, cutting search time. If you want that than your listboxes should
not be based
on the the tables but on your MAIN table.


Walter


"Damian" <codecharge@sydneyit.no.com.junk> schreef in bericht
news:ce1nc1$3ud$1@news.codecharge.com...
> Howdy again,
>
> I have a search form with the following list boxes
> [state]
> [ditrict]
> [town]
>
> The list box values are pulled from the following tables
> state (id,country,state)
> district (id,state,ditrict)
> town (id,district,town)
>
> In state the value country is set oin the grid as a specific country.
> In district the value state needs to be set based on the value set above
(eg
> if you select state 100 above, then all districts in State 100 will show).
> In town the value district needs to be set based on the value set in
> district (as above).
>
> Once the user selects the Town and submits the search then ALL members
from
> that Town should be displayed.
>
> My problem is getting the second and third listboxes to update their
> contents - ie someone selects the state, the ditricts update, they selcet
a
> district and the towns update. When they hit Submit and a town has been
> selected it will pass the town to the Search Results Grid.
>
> Any ideas...
>
>
>

DaveRexel

Posts: 50
Posted: 07/27/2004, 3:58 AM

::
This tutorial by Sixto with example CCS project file might help

http://ccs.ath.cx/~ccs/kb.php?language_id=7&category_id=44&event_id=98

_________________
/Dave
RexDesign CodeCharge Studio Tutorials
http://rexdesign.com/ccs/
View profile  Send private message
Walter Kempees
Posted: 07/27/2004, 6:09 AM

Using the example tables below this would be a/my approach:
Assuming that the main table, the one the search and grid runs on has a
layout of
members(id, name, countryid, stateid, districtid, townid, .......)
country(id,country)
state (id,country,state)
district (id,state,ditrict)
town (id,district,town)

Create, using the builder a search/grid on MEMBERS with country, state,
district, town as search fields and
id, name, country, state, district, town as fields in the list.
Now first make everything work as normally, in the process, in the GRID,
changing the countryid, stateid, districtid and townid to displaying the
lookup values of the respective tables.
Only if you didn't do this in the builder already.
This will involve changing the SQL in the list to link to the respective
tables.
Get this to work first.
Next change the SQL in the list and add a where clause.
If this search/grid is generated, the search field will be called
s_countryid, s_stateid, s_districtid and s_townid and the SQL will be
already in place.
Change (or add) the where clause to:
members.countryid={s_countrid} and
members.stateid = {s_stateid} and
members.districtid = {s_districtid} and
members.townid = {s_townid}

Now save, generate and test your search/grid, any values given in the search
fields should result in the correct data in the grid.

Next in the Search part of the page, change the search field s_scountryid to
type: list box.
In the properties, data section, Click the datasource elipsis (...) ,
DataSourceType should be SQL,
statement SELECT id, country FROM country
Bound Column =
Text column =
Data Type = Text

Save, generate and test.
Should result in the same working page, except that for country you can
choose values from a list.

Next:
in the Search part of the page, change the search field s_stateid to type
list box.
In the properties, data section, Click the datasource elipsis (...) ,
DataSourceType should be SQL,
statement SELECT id, state FROM state where countryid = {s_country_id}
While changing this look at the Parameter section of the DataSource Window,
click the '+' sign to add a parameter.
Variable should be s_countryid, type Integer, Parameter s_countryid, Type
Control, give it a default value.
click ok and in the Properties, Data check
Bound Column =
Text column =
Data Type = Text

Following this scheme do the same for district and town.

It pays off to do a save, generate test after each step. Although
progressing slowly at least you will know where things go wrong if they do.

If all is well this should be the result upto now:
If you enter your page for the first time all list boxes will display the
default value (Select value).
Choose a value from country listbox and press SEARCH button, the screen
refreshes and displays your chosen value in country listox, now click the
state box
if all is well this should display choices only related to the value in
country, and so on displaying the appropriate records in the grid as you go
along.

If this works, then you are ready for the final step.
Simple and final step, go to the property window for each listbox, events
tab.
In the Client side events of the listbox you will find OnChange action,
right click this and choose [add action], the action you want is [submit
form].
Do this for each box and your search/grid with dependant listboxes should
work like a charm.

Donated
Walter

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.