I suck at explaining code so here is my explanation in code� (doesn�t mean
it works)

<!--- make a valid list of tables to choose from for the second field --->

<cfset goodtables = "clients,client_tests,whateverelse">

<!--- make a list of displaytext for the good tables (positions must match)
--->

<cfset displaytext = "CLients,Client Tests,Whatever Else">

<!--- make sure the field exists and has a valid table to choose from --->

<cfif isdefined("form.firstfield") and listfindnocase(goodtables,
form.firstfield)>

            <cfset GetSecondRecs = True>

<cfelse>

            <cfset GetSecondRecs = False>

</cfif>

<!--- if getsecondrecs is true then get the records form the table that is
in the list at form.firstfields position--->

<!--- you could make the values of the fields the names of the tables, but I
wouldnt suggest putting your table names in plain view --->

<cfif GetSecondRecs>

            <cfquery name="MyQuery" datasource="#datasource#">

            Select Record from #ListGetat(goodtables, form.firstfield)#

            </cfquery>

</cfif>

<cfoutput>

<form name="test" action="" method="post">

<select name="firstfield" size="1" >
            <option value="0">--- MAKE A SELECTION ---</option>

            <cfloop from="1" to="#listLen(goodtables)#" index="i">

            <option value="#i#"<cfif form.firstfield is i>
selected</cfif>>#listgetat(displaytext, i)#</option>

            </cfloop>

</select>

            

<select name="secondfield" size="1">

            <option value="0">--- MAKE A SELECTION ---</option>

            <cfif GetSecondRecs>   

                        <cfloop query="MyQuery">

                                    <option value="#recordid#"<cfif
form.firstfield is recorded> selected</cfif>>#displaytext#</option>

                        </cfloop>

            </cfif>

</select>

<br />

<input type="submit" name="submitit" value="submit me" />

</form>

</cfoutput>



<!--- only include your action page (or next page) if the submit button was
used to submit --->

<cfif isdefined("form.submitme")>

The button was clicked so do your validation and continue on from here

</cfif>

This all looks in order. Just try changing the GoodTables list to your table
names and see what happens.

It should populate the first field initially, once a change is made on it,
it should submit and get the records from MyQuery  (which table depends on
the value of the first field) and populate the second field with it.

It should also remember the first field selection and keep it selected.

It should also only show the text �The button was clicked so do your
validation and continue on from here� when the submit button is actually
clicked and not when the onchange causes the submit.

Like I said, it LOOKS in order but I didn�t test it. But the whole thing
flows like what it sounds like you need.

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.759 / Virus Database: 508 - Release Date: 9/9/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.759 / Virus Database: 508 - Release Date: 9/9/2004
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to