This is a multi-part message in MIME format.

------=_NextPart_000_00FB_01C00386.96C88AC0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi Terri,

> I'm assuming I will have to (ugh) use a javascript for
> this?  Admittedly, I am neither a javascript guru nor
> a coldfusion guru. Can anyone provide me with some
> direction on this?

I've attached two files which I hope will start you going in the right
direction.  The first one doesn't specifically answer your question,
but does deal with dynamically repopulating a form
based on a selection.  In the hope that other people will also find it
useful.

In the first example I'm populating a second drop down select box,
based on the selection made in the first drop down box.

The second file should give you a better solution to your problem.
You'll need to tweek it slightly to suit your needs, but it's all
there.  I'm sure there are simpler ways to do this, but using the code
in the second file may allow you to move forwards to more elaborate
code/needs.  You'll notice I also have more than one person in a
department, where as you'll only be having one person per department,
this'll be reflected I assume in your database.

Good luck anyway.

Oh yeah, the code won't "run straight out of the box" as it depends on
two queries in a database, these are easy to build I've commented them
in the code.  Of course you'll also need to change the datasource.

I've put working examples up at...
http://www.phink.net/dynamicSelect.cfm
http://www.phink.net/dynamicSelect2.cfm

> Thanks in advance!
> Terri

Hope this helps someone.

Dan.



This message is intended only for the use of the person(s) ("the intended 
recipient(s)") to whom it is addressed.

It may contain information which is privileged and confidential within the meaning of 
the applicable law. If you are not the intended recipient, please contact the sender 
as soon as possible.The views expressed in this communication may not necessarily be 
the views held by Live Information Systems Limited.

------=_NextPart_000_00FB_01C00386.96C88AC0
Content-Type: application/octet-stream;
        name="dynamicSelect.cfm"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="dynamicSelect.cfm"

<!---=0A=
//  Title:    Dynamic Select Example=0A=
//  Created:  11th August 2000=0A=
//  By:       Daniel Kemp=0A=
--->=0A=
=0A=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">=0A=
=0A=
<html>=0A=
<head>=0A=
        <title>Untitled</title>=0A=
=0A=
<!--=0A=
//      Here we get all the info we need from the databases=0A=
--->=0A=
=0A=
<!--- These are my two tables, the first one; departments has the =
following fields...=0A=
//      id                      (int)                           The unique id of each 
department.=0A=
//      title           (varchar)               The title of each department.=0A=
//=0A=
//      The contents look somewhat like=0A=
//=0A=
//              id      |       title=0A=
//  ------|-------------=0A=
//               1      |       Development=0A=
//               2      |       Resources=0A=
//               3      |       Sales=0A=
--->=0A=
=0A=
<cfquery name=3D"departments" datasource=3D"yme" dbtype=3D"ODBC">=0A=
  SELECT *=0A=
        FROM departments=0A=
        ORDER BY title=0A=
</cfquery>=0A=
=0A=
<!--- The second; staff has the following fields...=0A=
//      id                                                      (int)                  
         The unique id of each member of staff=0A=
//      departmentID            (int)                           The department they 
are in=0A=
//      title                                           (varchar)               The 
staff members name=0A=
//=0A=
//      The contents look somewhat like=0A=
//=0A=
//      id      | departmentID | title=0A=
//    ------|----------------------=0A=
//       1      |      1       | Bill=0A=
//       2      |      1       | Colin=0A=
//       3      |      2       | Dave=0A=
//       4      |      3       | Eve=0A=
//       5      |      2       | Fiona=0A=
//       6      |      3       | George=0A=
//       7      |      1       | Helen=0A=
//       8      |      3       | Ian=0A=
//=0A=
//      Notice in this case I have more then one member of staff in each =
department, this is=0A=
//      to open up the uses of this JavaScript to more people, in Terri's =
case there's only=0A=
//      one default person in each department.=0A=
--->=0A=
=0A=
<cfquery name=3D"staff" datasource=3D"yme" dbtype=3D"ODBC">=0A=
        SELECT *=0A=
        FROM staff=0A=
        ORDER BY title=0A=
</cfquery>=0A=
=0A=
<!---=0A=
//      Now onto the funky JavaScript=0A=
--->=0A=
<script language=3D"JavaScript">=0A=
=0A=
<!---=0A=
//      This function is kinda like creating our own object like thing, =
anyway it's an object=0A=
//      called anyStaff, which has three properties.  I can use it as such...=0A=
//      anyStaff.ID =3D 1=0A=
//      anyStaff.title =3D 'Tony'=0A=
//      anyStaff.departmentID =3D 6=0A=
--->=0A=
=0A=
        function anyStaff(ID,title,departmentID) {=0A=
                this.ID =3D ID;=0A=
                this.title =3D title;=0A=
                this.departmentID =3D departmentID;=0A=
        }=0A=
=0A=
        <cfoutput>=0A=
<!---=0A=
//      We are now setting myStaff to be an array of the anyStaff object we =
defined above,=0A=
//      therefore we can now go...=0A=
//      myStaff[0].ID =3D 1=0A=
//      myStaff[0].title =3D 'bengy'=0A=
//      etc. etc. for each member of staff we have=0A=
--->=0A=
                var maxStaff =3D #staff.RecordCount#;=0A=
                myStaff =3D new Array(maxStaff);=0A=
        </cfoutput>=0A=
=0A=
<!---=0A=
//      And this is the bit that loads up the array,=0A=
--->=0A=
        <cfset counter =3D 0>=0A=
        <cfoutput query=3D"staff">=0A=
                myStaff[#counter#] =3D new 
anyStaff('#ID#','#title#','#departmentID#');=0A=
     <cfset counter =3D counter + 1>=0A=
        </cfoutput>=0A=
<!---=0A=
//      The best way to see what happened is to view the source code created, =
which should look something like...=0A=
//              myStaff[0] =3D new anyStaff('1','Bill','1');=0A=
//              myStaff[1] =3D new anyStaff('2','Colin','1');=0A=
//              myStaff[2] =3D new anyStaff('3','Dave','2');=0A=
//              myStaff[3] =3D new anyStaff('4','Eve','3');=0A=
//              myStaff[4] =3D new anyStaff('5','Fiona','2');=0A=
//              myStaff[5] =3D new anyStaff('6','George','3');=0A=
//              myStaff[6] =3D new anyStaff('7','Helen','1');=0A=
//              myStaff[7] =3D new anyStaff('8','Ian','3');=0A=
--->=0A=
                =0A=
=0A=
<!---=0A=
//      This function does all the hard work, when someone changes the =
selection in the department box=0A=
//      this function is called.  To start with it empties out the staff =
select box, then it attempts=0A=
//      to re-populate it.  It starts with adding two default lines, and then =
loops though all the=0A=
//      myStaff objects we created above, checking to see if their =
departmentID matches the ID given=0A=
//      to use from the department select box.=0A=
--->=0A=
                function changeStaff() {=0A=
                        //      Empty out the staff list box.=0A=
                        document.formName.dropdown2.length =3D 0;=0A=
                        //      Get the current department ID value.=0A=
                        var departmentID =3D =
document.formName.dropdown1.options[document.formName.dropdown1.selectedI=
ndex].value;=0A=
      //        Add the 2 default lines.=0A=
                        document.formName.dropdown2.options[0] =3D new Option('Select 
a staff =
member',-99);=0A=
          document.formName.dropdown2.options[1] =3D new =
Option('------------------------------------------------------',-99);=0A=
                        //      Set the counter up to add the rest of the recrods.=0A=
                        var counter =3D 2;=0A=
                        //      Now loop through the staff to find the people who 
belong in this =
department.=0A=
                        for (var i =3D 0; i < maxStaff;i++) {=0A=
                                //      If this member of staffs departmentID matches 
the currently =
selected department ID=0A=
                                //      then we add them=0A=
                                if (myStaff[i].departmentID =3D=3D departmentID) {=0A=
                                        document.formName.dropdown2.options[counter] 
=3D new =
Option(myStaff[i].title,myStaff[i].ID);=0A=
                                        counter =3D counter + 1;=0A=
                                }=0A=
                        }=0A=
                }=0A=
                =0A=
        </script>=0A=
=0A=
</HEAD>=0A=
=0A=
<body>=0A=
=0A=
<!---=0A=
//      This is the form=0A=
--->=0A=
=0A=
<form action=3D"doSometing.cfm" method=3D"post" name=3D"formName" =
enctype=3D"multipart/form-data">=0A=
<table>=0A=
  <tr>=0A=
    <td>=0A=
      Department:=0A=
    </td>=0A=
    <td>=0A=
      <select name=3D"department" size=3D"1" id=3D"dropdown1" =
onChange=3D"changeStaff(this.form,this.selectedIndex)">=0A=
              <option value=3D"-99">Select a department</option>=0A=
          <option =
value=3D"-99">------------------------------------------------------</opt=
ion>=0A=
                  <cfoutput query=3D"departments">=0A=
                          <option value=3D#id#>#title#</option>=0A=
                </cfoutput>                             =0A=
      </select>=0A=
    </td>=0A=
  </tr>=0A=
    =0A=
  <tr>=0A=
    <td>=0A=
      Staff:=0A=
    </td>=0A=
    <td>=0A=
      <select name=3D"staff" size=3D"1" ID=3D"dropdown2">=0A=
          <option =
value=3D"-99">------------------------------------------------------</opt=
ion>=0A=
      </select>=0A=
    </td>=0A=
  </tr>=0A=
</table>=0A=
</form>=0A=
=0A=
</body>=0A=
</html>
------=_NextPart_000_00FB_01C00386.96C88AC0
Content-Type: application/octet-stream;
        name="dynamicSelect2.cfm"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="dynamicSelect2.cfm"

<!---=0A=
//  Title:    Dynamic Select Example=0A=
//  Created:  11th August 2000=0A=
//  By:       Daniel Kemp=0A=
--->=0A=
=0A=
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">=0A=
=0A=
<html>=0A=
<head>=0A=
        <title>Untitled</title>=0A=
=0A=
<!--=0A=
//      Here we get all the info we need from the databases=0A=
--->=0A=
=0A=
<!--- These are my two tables, the first one; departments has the =
following fields...=0A=
//      id                      (int)                           The unique id of each 
department.=0A=
//      title           (varchar)               The title of each department.=0A=
//=0A=
//      The contents look somewhat like=0A=
//=0A=
//              id      |       title=0A=
//  ------|-------------=0A=
//               1      |       Development=0A=
//               2      |       Resources=0A=
//               3      |       Sales=0A=
--->=0A=
=0A=
<cfquery name=3D"departments" datasource=3D"yme" dbtype=3D"ODBC">=0A=
  SELECT *=0A=
        FROM departments=0A=
        ORDER BY title=0A=
</cfquery>=0A=
=0A=
<!--- The second; staff has the following fields...=0A=
//      id                                                      (int)                  
         The unique id of each member of staff=0A=
//      departmentID            (int)                           The department they 
are in=0A=
//      title                                           (varchar)               The 
staff members name=0A=
//=0A=
//      The contents look somewhat like=0A=
//=0A=
//      id      | departmentID | title=0A=
//    ------|----------------------=0A=
//       1      |      1       | Bill=0A=
//       2      |      1       | Colin=0A=
//       3      |      2       | Dave=0A=
//       4      |      3       | Eve=0A=
//       5      |      2       | Fiona=0A=
//       6      |      3       | George=0A=
//       7      |      1       | Helen=0A=
//       8      |      3       | Ian=0A=
//=0A=
//      Notice in this case I have more then one member of staff in each =
department, this is=0A=
//      to open up the uses of this JavaScript to more people, in Terri's =
case there's only=0A=
//      one default person in each department.=0A=
--->=0A=
=0A=
<cfquery name=3D"staff" datasource=3D"yme" dbtype=3D"ODBC">=0A=
        SELECT *=0A=
        FROM staff=0A=
        ORDER BY title=0A=
</cfquery>=0A=
=0A=
<!---=0A=
//      Now onto the funky JavaScript=0A=
--->=0A=
<script language=3D"JavaScript">=0A=
=0A=
<!---=0A=
//      This function is kinda like creating our own object like thing, =
anyway it's an object=0A=
//      called anyStaff, which has three properties.  I can use it as such...=0A=
//      anyStaff.ID =3D 1=0A=
//      anyStaff.title =3D 'Tony'=0A=
//      anyStaff.departmentID =3D 6=0A=
--->=0A=
=0A=
        function anyStaff(ID,title,departmentID) {=0A=
                this.ID =3D ID;=0A=
                this.title =3D title;=0A=
                this.departmentID =3D departmentID;=0A=
        }=0A=
=0A=
        <cfoutput>=0A=
<!---=0A=
//      We are now setting myStaff to be an array of the anyStaff object we =
defined above,=0A=
//      therefore we can now go...=0A=
//      myStaff[0].ID =3D 1=0A=
//      myStaff[0].title =3D 'bengy'=0A=
//      etc. etc. for each member of staff we have=0A=
--->=0A=
                var maxStaff =3D #staff.RecordCount#;=0A=
                myStaff =3D new Array(maxStaff);=0A=
        </cfoutput>=0A=
=0A=
<!---=0A=
//      And this is the bit that loads up the array,=0A=
--->=0A=
        <cfset counter =3D 0>=0A=
        <cfoutput query=3D"staff">=0A=
                myStaff[#counter#] =3D new 
anyStaff('#ID#','#title#','#departmentID#');=0A=
     <cfset counter =3D counter + 1>=0A=
        </cfoutput>=0A=
<!---=0A=
//      The best way to see what happened is to view the source code created, =
which should look something like...=0A=
//              myStaff[0] =3D new anyStaff('1','Bill','1');=0A=
//              myStaff[1] =3D new anyStaff('2','Colin','1');=0A=
//              myStaff[2] =3D new anyStaff('3','Dave','2');=0A=
//              myStaff[3] =3D new anyStaff('4','Eve','3');=0A=
//              myStaff[4] =3D new anyStaff('5','Fiona','2');=0A=
//              myStaff[5] =3D new anyStaff('6','George','3');=0A=
//              myStaff[6] =3D new anyStaff('7','Helen','1');=0A=
//              myStaff[7] =3D new anyStaff('8','Ian','3');=0A=
--->=0A=
                =0A=
=0A=
<!---=0A=
//      This function does all the hard work, when someone changes the =
selection in the department box=0A=
//      this function is called.  To start with it deselects all the items in =
the dropdown2 box, then it=0A=
//      Then it loops though all the list of staff members, finding out if =
they belong to that department.=0A=
//      Using the myStaff objects we created above, checking to see if their =
departmentID matches the ID =0A=
//      given to use from the department select box, if so make that item =
number selected.  We use a counter=0A=
//      to keep track of how far we are through the list.=0A=
--->=0A=
                function changeStaff() {=0A=
                        //      Deselects all the items=0A=
                        for (var i =3D 0; i < maxStaff;i++) {=0A=
                                document.formName.dropdown2.options[i].selected =3D 
false;=0A=
                        }=0A=
                        //      Get the current department ID value.=0A=
                        var departmentID =3D =
document.formName.dropdown1.options[document.formName.dropdown1.selectedI=
ndex].value;=0A=
                        var counter =3D 0;=0A=
                        //      Now loop through the staff to find the people who 
belong in this =
department.=0A=
                        for (var i =3D 0; i < maxStaff;i++) {=0A=
                                //      If this member of staffs departmentID matches 
the currently =
selected department ID=0A=
                                //      then we make them selected.=0A=
                                if (myStaff[i].departmentID =3D=3D departmentID) {=0A=
                                        
document.formName.dropdown2.options[counter].selected =3D true;=0A=
                                }=0A=
                                // add one to the counter, to move us onto the next 
record.=0A=
                                counter =3D counter + 1;=0A=
                        }=0A=
                }=0A=
                =0A=
        </script>=0A=
=0A=
</HEAD>=0A=
=0A=
<body>=0A=
=0A=
<!---=0A=
//      This is the form=0A=
--->=0A=
=0A=
<form action=3D"doSometing.cfm" method=3D"post" name=3D"formName" =
enctype=3D"multipart/form-data">=0A=
<table>=0A=
  <tr>=0A=
    <td>=0A=
      Department:=0A=
    </td>=0A=
    <td>=0A=
      <select name=3D"department" size=3D"1" id=3D"dropdown1" =
onChange=3D"changeStaff(this.form,this.selectedIndex)">=0A=
              <option value=3D"-99">Select a department</option>=0A=
          <option =
value=3D"-99">------------------------------------------------------</opt=
ion>=0A=
                  <cfoutput query=3D"departments">=0A=
                          <option value=3D#id#>#title#</option>=0A=
                </cfoutput>                             =0A=
      </select>=0A=
    </td>=0A=
  </tr>=0A=
    =0A=
  <tr>=0A=
    <td valign=3D"top">=0A=
      Staff:=0A=
    </td>=0A=
    <td>=0A=
      <select name=3D"staff" size=3D"8" ID=3D"dropdown2" multiple>=0A=
                                <cfoutput query=3D"staff">=0A=
                  <option value=3D"#id#">#title#</option>=0A=
                                </cfoutput>=0A=
      </select>=0A=
    </td>=0A=
  </tr>=0A=
</table>=0A=
</form>=0A=
=0A=
</body>=0A=
</html>
------=_NextPart_000_00FB_01C00386.96C88AC0--


------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to