Hi Paul,

It seems like you're a little unclear on what's server-side and what's
client-side.

CF and SQL run entirely on the server, whereas Javascript runs entirely
on the web browser, i.e. AFTER all the server-side stuff has finished
executing, and the complete page has been sent to the browser.

For two related select boxes, you can either
- Have the page make a separate trip to the server whenever the first
select box is changed. This can be a bit annoying for the user, and also
means you have to make sure the rest of the form gets re-populated with
the previously entered values
Or
- do the whole thing on the browser using javascript arrays. How useful
this option is depends largely on how many options IN TOTAL are in the
two select boxes - any more than a hundred or so, and browsers will
start to slow down.

I usually go for the first option - rough-and-ready-code below.

Given two tables :

tblMaster
intMasterID
vcTitle 
(or whatever)

tblServant
intServantID
intMasterID
vcTitle 
(or whatever)

I'd do something like this:

<cfparam name="masterID" default="0" />
<cfparam name="servantID" default="0" />
<cfparam name="frmAction" default="" />

<!--- if we've completed the form --->
<cfif frmAction EQ "process">
        <cfset intErrorCount = 0 />
        <!--- CHECK FORM RESULTS FOR ERRORS HERE --->

        <cfif intErrorCount EQ 0>
                <!--- PROCESS THE RESULTS OF THE FORM HERE --->
                <!--- ... --->
                <!--- DONE ALL PROCESSING, GO TO NEXT PAGE --->
                <cflocation url="(next page)" />
        </cfif>
        
</cfif>


<!--- get master records --->
<cfquery name="qryMaster">
        SELECT * FROM tblMaster
        ORDER BY vcTitle
</cfquery>

<!--- get servant records --->
<cfquery name="qryServant">
        SELECT * FROM tblServant
        WHERE intMasterID = <cfqueryparam cfsqltype="CF_SQL_INTEGER"
value="#intMasterID#" />
        ORDER BY vcTitle
</cfquery>

<cfoutput>
<script language="javascript">
        function masterChanged(frm){
                // change the action on the form
                frm.frmAction.value = "refresh";
                frm.submit();
        }
</script>
<form action="#cgi.script_name#" method="POST">
        <!--- hidden action field says whether we're refreshing the form
--->
        <!--- or going to the next page --->
        <input type="hidden" name="frmAction" value="process" />

        <!--- first select --->
        <p>
                <select name="masterID"
onchange="masterChanged(this.form);">
                        <option value="0">Please select</option>
                <cfloop query="qryMaster">
                        <option value="#qryMaster.intMasterID#" <cfif
intMasterID EQ
qryMaster.intMasterID>SELECTED</cfif>>#qryMaster.vcTitle#</option>
                </cfloop>
                </select>
        </p>

        <!--- second, related select --->
        <p>
                <select name="servantID">
                        <option value="0">Please select</option>
                <cfloop query="qryServant">
                        <option value="#qryServant.intServantID#" <cfif
servantID EQ
qryServant.intServantID>SELECTED</cfif>>#qryServant.vcTitle#</option>
                </cfloop>
                </select>
        </p>
        <p>
                <input type="submit" value="next page" />
        </p>
</form>

</cfoutput>

I haven't tested this code, so there may be a couple of typos in it, but
the principle is this - 

- the default master id is zero. So at first, your second select will be
empty
- once the first select is changed, the javascript will submit the form
BACK TO THE SAME PAGE. You will then have a non-zero mastered, and the
second select will be populated with related records

Hope that helps - try to make sure you understand WHY and HOW it works

Happy coding

Alistair Davidson
Senior Technical Developer
Headshift.com
Smarter, Simpler, Social

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: 26 May 2004 08:31
To: [EMAIL PROTECTED]
Subject: [ cf-dev ] Relative Select List


Having read an old Javascript book last night I now have ....

WHERE (Menu_Group =
Selected_menu.options[selected_menu.options.selectedIndex].value;)

As expected this doesn't work either .... :(

Can anyone help me with this one please? - My JavaScript is "even more
worserer" than my Coldfusion (if it could be worse...)


Regards - Paul




************************************************************************
*************************
The information contained within this e-mail (and any attachment) sent
by Birmingham City Council is confidential and may be legally
privileged. It is intended only for the named recipient or entity to
whom it is addressed. If you are not the intended recipient please
accept our apologies and notify the sender immediately, or telephone
+(44) 121 303 6666. Unauthorised access, use, disclosure, storage or
copying is not permitted and may be unlawful. Any e-mail including its
content may be monitored and used by Birmingham City Council for reasons
of security and for monitoring internal compliance with the office
policy on staff use. E-mail blocking software may also be used. Any
views or opinions presented are solely those of the originator and do
not necessarily represent those of Birmingham City Council. We cannot
guarantee that this message or any attachment is virus free or has not
been intercepted and amended.

************************************************************************
*************************


-- 
These lists are syncronised with the CFDeveloper forum at
http://forum.cfdeveloper.co.uk/
Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
 
CFDeveloper Sponsors and contributors:-
*Hosting and support provided by CFMXhosting.co.uk* :: *ActivePDF
provided by activepdf.com*
      *Forums provided by fusetalk.com* :: *ProWorkFlow provided by
proworkflow.com*
           *Tutorials provided by helmguru.com* :: *Lists hosted by
gradwell.com*

To unsubscribe, e-mail: [EMAIL PROTECTED]



--
These lists are syncronised with the CFDeveloper forum at 
http://forum.cfdeveloper.co.uk/
Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

CFDeveloper Sponsors and contributors:-
*Hosting and support provided by CFMXhosting.co.uk* :: *ActivePDF provided by 
activepdf.com*
      *Forums provided by fusetalk.com* :: *ProWorkFlow provided by proworkflow.com*
           *Tutorials provided by helmguru.com* :: *Lists hosted by gradwell.com*

To unsubscribe, e-mail: [EMAIL PROTECTED]

Reply via email to