jollymon6672
asked on
CFQuery for a Tri-Dependent Select
I am trying to use the <CF_ThreeSelectsRelated> tag.
I am having trouble getting it to work:
QUERY:
<!--- Query - Country/County/State --->
<cfquery name="rsTriSelect" datasource="#mm_datasource _dsn#">
SELECT tbl_countries.CountryID, tbl_countries.Country, tbl_postalCode.CountryID, tbl_postalCode.County, tbl_postalCode.State, tbl_postalCode.StateID
FROM tbl_postalCode, tbl_countries
INNER JOIN tbl_countries.CountryID ON tbl_postalCode.CountryID
</cfquery>
CODE:
<cfinclude template="qry_CountyStateC ity.cfm">
<form action="" method="post">
<CF_ThreeSelectsRelated
QUERY="rsTriSelect"
HTMLAFTER2="<BR>"
NAME1="Country"
NAME2="State"
NAME3="County"
VALUE1="tbl_countries.Coun tryID"
VALUE2="tbl_postalCode.Sta teCode"
VALUE3="tbl_postalCode.Cou nty"
DISPLAY1="tbl_countries.Co untry"
DISPLAY2="tbl_postalCode.S tate"
DISPLAY3="tbl_postalCode.C ounty"
DEFAULT1="254"
SIZE1="1"
SIZE2="1"
SIZE3="1"
WIDTH1="150"
WIDTH2="150"
WIDTH3="300"
FORCEWIDTH1="40"
FORCEWIDTH2="40"
FORCEWIDTH3="90"
AUTOSELECTFIRST="yes"
MULTIPLE3="no">
</form>
How difficult is it to make this a Quad Select (Country, State, County and City)?
I am having trouble getting it to work:
QUERY:
<!--- Query - Country/County/State --->
<cfquery name="rsTriSelect" datasource="#mm_datasource
SELECT tbl_countries.CountryID, tbl_countries.Country, tbl_postalCode.CountryID, tbl_postalCode.County, tbl_postalCode.State, tbl_postalCode.StateID
FROM tbl_postalCode, tbl_countries
INNER JOIN tbl_countries.CountryID ON tbl_postalCode.CountryID
</cfquery>
CODE:
<cfinclude template="qry_CountyStateC
<form action="" method="post">
<CF_ThreeSelectsRelated
QUERY="rsTriSelect"
HTMLAFTER2="<BR>"
NAME1="Country"
NAME2="State"
NAME3="County"
VALUE1="tbl_countries.Coun
VALUE2="tbl_postalCode.Sta
VALUE3="tbl_postalCode.Cou
DISPLAY1="tbl_countries.Co
DISPLAY2="tbl_postalCode.S
DISPLAY3="tbl_postalCode.C
DEFAULT1="254"
SIZE1="1"
SIZE2="1"
SIZE3="1"
WIDTH1="150"
WIDTH2="150"
WIDTH3="300"
FORCEWIDTH1="40"
FORCEWIDTH2="40"
FORCEWIDTH3="90"
AUTOSELECTFIRST="yes"
MULTIPLE3="no">
</form>
How difficult is it to make this a Quad Select (Country, State, County and City)?
ASKER
Any idea why my current code is not working?
ASKER
Ideally I would like to extend the tri-select tag to be a quad-select tag. I am trying use a postal data table and narrow down the slection choices:
Country:
State/Region:
County:
City:
Country:
State/Region:
County:
City:
You cannot modify the tag if you do not have the source code for it
ASKER
<!--- REMOVE THIS AND FIRST LINE IF NOT USING CF3.1 OR LATER --->
<CFSETTING ENABLECFOUTPUTONLY="YES">
<!--- TAG PARAMETERS --->
<CFPARAM NAME="Attributes.Query">
<CFPARAM NAME="Attributes.Type1" DEFAULT="Select">
<CFPARAM NAME="Attributes.HTMLAfter EachRadio1 " DEFAULT="">
<CFPARAM NAME="Attributes.Name1" DEFAULT="TwoSelectsRelated 1">
<CFPARAM NAME="Attributes.Name2" DEFAULT="TwoSelectsRelated 2">
<CFPARAM NAME="Attributes.Name3" DEFAULT="TwoSelectsRelated 3">
<CFPARAM NAME="Attributes.Value1">
<CFPARAM NAME="Attributes.Value2">
<CFPARAM NAME="Attributes.Value3">
<CFPARAM NAME="Attributes.Display1" DEFAULT="#Attributes.Value 1#">
<CFPARAM NAME="Attributes.Display2" DEFAULT="#Attributes.Value 2#">
<CFPARAM NAME="Attributes.Display2" DEFAULT="#Attributes.Value 3#">
<CFPARAM NAME="Attributes.Default1" DEFAULT="xxxxxxxxxxxx">
<CFPARAM NAME="Attributes.Default2" DEFAULT="xxxxxxxxxxxx">
<CFPARAM NAME="Attributes.Default3" DEFAULT="xxxxxxxxxxxx">
<CFPARAM NAME="Attributes.Multiple3 " DEFAULT="No">
<CFPARAM NAME="Attributes.Size1" DEFAULT="1">
<CFPARAM NAME="Attributes.Size2" DEFAULT="1">
<CFPARAM NAME="Attributes.Size3" DEFAULT="1">
<CFPARAM NAME="Attributes.ExtraOpti ons2" DEFAULT="">
<CFPARAM NAME="Attributes.ExtraOpti ons3" DEFAULT="">
<CFPARAM NAME="Attributes.Width1" DEFAULT="">
<CFPARAM NAME="Attributes.Width2" DEFAULT="">
<CFPARAM NAME="Attributes.Width3" DEFAULT="">
<CFPARAM NAME="Attributes.ForceWidt h1" DEFAULT="">
<CFPARAM NAME="Attributes.ForceWidt h2" DEFAULT="">
<CFPARAM NAME="Attributes.ForceWidt h4" DEFAULT="">
<CFPARAM NAME="Attributes.ForceWidt hChar" DEFAULT=" ">
<CFPARAM NAME="Attributes.EmptyText 1" DEFAULT="">
<CFPARAM NAME="Attributes.EmptyText 2" DEFAULT="">
<CFPARAM NAME="Attributes.EmptyText 3" DEFAULT="">
<CFPARAM NAME="Attributes.Message1" DEFAULT="You must choose an option for #Attributes.Name1#.">
<CFPARAM NAME="Attributes.Message2" DEFAULT="You must choose an option for #Attributes.Name2#.">
<CFPARAM NAME="Attributes.Message3" DEFAULT="You must choose an option for #Attributes.Name3#.">
<CFPARAM NAME="Attributes.FormName" DEFAULT="forms[0]">
<CFPARAM NAME="Attributes.HTMLAfter 1" DEFAULT="">
<CFPARAM NAME="Attributes.HTMLAfter 2" DEFAULT="">
<CFPARAM NAME="Attributes.OnChange" DEFAULT="">
<CFPARAM NAME="Attributes.AutoSelec tFirst" DEFAULT="Yes">
<CFIF Attributes.Type1 is "Radio">
<CFSET Attributes.EmptyText1 = "">
<CFSET Attributes.ForceWidth1 = "">
</CFIF>
<CFSET FunctionName = ReplaceList(Attributes.For mName, "[,]", ",") & "ChangeMenu">
<CFSET FunctionName2 = ReplaceList(Attributes.For mName, "[,]", ",") & "ChangeMenu2">
<!--- "MAGIC" SHORTCUTS FOR THE ONCHANGE HANDLER --->
<CFIF Attributes.OnChange is "Jump!">
<CFSET Attributes.OnChange = "document.location = this.options[selectedIndex ].value;">
<CFELSEIF Attributes.OnChange is "Submit!">
<CFSET Attributes.OnChange = "this.form.submit();">
</CFIF>
<!--- USE PASSED QUERY WITHIN THIS CODE AS "MyQuery" --->
<CFSET MyQuery = Evaluate("Caller.#Attribut es.Query#" )>
<!--- BEGIN JAVASCRIPTING --->
<CFOUTPUT>
<SCRIPT LANGUAGE="JavaScript1.1">
// javascript code generated by the CF_TwoSelectsRelated Cold Fusion tag (Nate Weiss, 4/98)
// portions adapted from Nick Heinle's code at http://webreference.com/javascript/960902/select_boxes.html
var maxlength = 10;
OneA = new Array;
var trueLength = OneA.length;
var lst = OneA.length;
var Trak = 0;
function require_#Attributes.Name1# () {
with (document.#Attributes.Form Name#.#Att ributes.Na me1#) {
RetVal = true;
if (Trak == -1) RetVal = false;
<CFIF Attributes.Type1 is "Select">
else RetVal = !(options[Trak].value == '');
<CFELSEIF Attributes.Type1 is "Radio">
else { if (document.#Attributes.Form Name#.#Att ributes.Na me1#[Trak] .value == '') RetVal = false; else RetVal = true;}
</CFIF>
if (!RetVal) alert('#Attributes.Message 1#');
return RetVal;
}
}
function require_#Attributes.Name2# () {
with (document.#Attributes.Form Name#.#Att ributes.Na me2#) {
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v alue == '');
if (!RetVal) alert('#Attributes.Message 2#');
return eval(RetVal);
return RetVal;
}
}
function require_#Attributes.Name3# () {
with (document.#Attributes.Form Name#.#Att ributes.Na me3#) {
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v alue == '');
if (!RetVal) alert('#Attributes.Message 3#');
return RetVal
}
}
function require_#Attributes.Name1# And#Attrib utes.Name2 #() {
return ((require_#Attributes.Name 1#()) && (require_#Attributes.Name2 #()));
}
function require_#Attributes.Name2# And#Attrib utes.Name3 #() {
return ((require_#Attributes.Name 2#()) && (require_#Attributes.Name3 #()));
}
function require_#Attributes.Name1# And#Attrib utes.Name2 #And#Attri butes.Name 3#() {
return ((require_#Attributes.Name 1#And#Attr ibutes.Nam e2#()) && (require_#Attributes.Name3 #()));
}
function #FunctionName#(menuNum) {
OneA.length = 0;
if (menuNum == null) return;
Trak = menuNum;
<!--- ignore if a blank item gets clicked --->
<CFIF Attributes.Type1 is "Select">
if (document.#Attributes.Form Name#.#Att ributes.Na me1#.optio ns[menuNum ].value == '') return;
if (document.#Attributes.Form Name#.#Att ributes.Na me1#.optio ns[menuNum ].value == null) return;
</CFIF>
</CFOUTPUT>
<!--- COUNTER VARIABLE WILL HOLD NUMBER OF GROUPS (OPTIONS IN FIRST SELECT) --->
<CFSET Counter = IIF(Attributes.EmptyText1 is not "", 1, 0)>
<!--- CREATE AN "IF" STATEMENT THAT COVERS EACH ITEM IN THE FIRST SELECT BOX --->
<!--- WITHIN THE "IF" STATMENT, PRE-POPULATE ARRAY WITH CORRESPONDING ITEMS FOR SECOND SELECT --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display 1#">
if (menuNum == #Counter#) {
NewOpt = new Array;
NewVal = new Array;
<CFSET Counter2 = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFIF Attributes.EmptyText2 is not ""><CFOUTPUT>NewOpt[0] = new Option("#Attributes.EmptyT ext2#"); NewOpt[0].value = ''; </CFOUTPUT></CFIF>
<CFOUTPUT GROUP="#Attributes.Display 2#">NewOpt [#Counter2 #] = new Option("#Evaluate(Attribut es.Display 2)#"); NewOpt[#Counter2#].value = '#Evaluate(Attributes.Valu e2)#'; <CFSET Counter2 = Counter2 + 1></CFOUTPUT>
} <CFSET Counter = Counter + 1>
</CFOUTPUT>
<!--- finish up the ChangeMenu() function --->
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormN ame#.#Attr ibutes.Nam e2#.option s.length;
for (i = lst; i > 0; i--) {
document.#Attributes.FormN ame#.#Attr ibutes.Nam e2#.option s[i] = null;
}
for (i = 0; i < tot; i++) {
document.#Attributes.FormN ame#.#Attr ibutes.Nam e2#.option s[i] = NewOpt[i];
}
<!--- <CFIF Attributes.AutoSelectFirst is "Yes"> --->
document.#Attributes.FormN ame#.#Attr ibutes.Nam e2#.option s[0].selec ted = true;
<!--- </CFIF> --->
#FunctionName2#(0);
}
</CFOUTPUT>
<!--- ALLOW FOR AUTO-SIZING "SHORTCUT" OF SELECT BOXES --->
<CFIF Attributes.Size1 is "Auto">
<!--- MAKE THE FIRST SELECT BE BIG ENOUGH FOR ALL OF ITS OPTIONS --->
<CFSET Attributes.Size1 = Counter>
</CFIF>
<CFIF Attributes.Size2 is "Auto">
<!--- MAKE THE SECOND SELECT BE THE SAME SIZE AS THE FIRST --->
<CFSET Attributes.Size2 = Attributes.Size1>
</CFIF>
<CFIF Attributes.Size3 is "Auto">
<!--- MAKE THE SECOND SELECT BE THE SAME SIZE AS THE FIRST --->
<CFSET Attributes.Size3 = Attributes.Size1>
</CFIF>
<CFOUTPUT>
function #FunctionName2#() {
OneA.length = 0;
menuNum = Trak;
//menuNum = document.#Attributes.FormN ame#.#Attr ibutes.Nam e1#.select edIndex;
menuNum2 = document.#Attributes.FormN ame#.#Attr ibutes.Nam e2#.select edIndex;
if (menuNum == -1) return;
if (menuNum2 == null) return;
<!--- ignore if a the blank item gets clicked --->
if (document.#Attributes.Form Name#.#Att ributes.Na me2#.optio ns[menuNum 2].value == '') return;
</CFOUTPUT>
<!--- COUNTER VARIABLE WILL HOLD NUMBER OF GROUPS (OPTIONS IN FIRST SELECT) --->
<CFSET Counter1 = 0>
<!--- CREATE AN "IF" STATEMENT THAT COVERS EACH ITEM IN THE FIRST SELECT BOX --->
<!--- WITHIN THE "IF" STATMENT, PRE-POPULATE ARRAY WITH CORRESPONDING ITEMS FOR SECOND SELECT --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display 1#">
if (menuNum == #Counter1#) {
<CFSET Counter = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFOUTPUT GROUP="#Attributes.Display 2#">
if (menuNum2 == #Counter#) {
NewOpt = new Array;
NewVal = new Array;
<CFSET Counter2 = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFIF Attributes.EmptyText3 is not "">NewOpt[0] = new Option("#Attributes.EmptyT ext3#"); NewOpt[0].value = ''; </CFIF>
<CFOUTPUT>
NewOpt[#Counter2#] = new Option("#Evaluate(Attribut es.Display 3)#");
NewOpt[#Counter2#].value = '#Evaluate(Attributes.Valu e3)#';
<CFSET Counter2 = Counter2 + 1>
</CFOUTPUT>
} <CFSET Counter = Counter + 1>
</CFOUTPUT>
} <CFSET Counter1 = Counter1 + 1>
</CFOUTPUT>
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormN ame#.#Attr ibutes.Nam e3#.option s.length;
for (i = lst; i > 0; i--) {
document.#Attributes.FormN ame#.#Attr ibutes.Nam e3#.option s[i] = null;
}
for (i = 0; i < tot; i++) {
document.#Attributes.FormN ame#.#Attr ibutes.Nam e3#.option s[i] = NewOpt[i];
}
<CFIF Attributes.AutoSelectFirst is "Yes">
document.#Attributes.FormN ame#.#Attr ibutes.Nam e3#.option s[0].selec ted = true;
</CFIF>
}
</SCRIPT>
</CFOUTPUT>
<!--- DONE WITH JAVASCRIPTING. NOW WE JUST HAVE TO DISPLAY THE FORM ELEMENTS --->
<!--- OUTPUT FIRST FORM ELEMENT --->
<CFIF Attributes.Type1 is "Select">
<CFOUTPUT><SELECT NAME="#Attributes.Name1#" onChange="#FunctionName#(t his.select edIndex)" SIZE="#Attributes.Size1#" <CFIF Attributes.Width1 is not "">STYLE="width:#Attribute s.Width1#" </CFIF>></ CFOUTPUT>
<!--- SPECIAL FIRST ITEM, IF REQUESTED --->
<CFIF Attributes.EmptyText1 is not ""><CFOUTPUT><OPTION VALUE="">#Attributes.Empty Text1#</CF OUTPUT></C FIF>
<!--- GENERATE REMAINING ITEMS FROM QUERY --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display 1#"><OPTIO N VALUE="#Evaluate(Attribute s.Value1)# " <CFIF Evaluate(Attributes.Value1 ) is Attributes.Default1>SELECT ED</CFIF>> #Evaluate( Attributes .Display1) #</CFOUTPU T>
<!--- "FORCE WIDTH" OPTION AT BOTTOM, IF REQUESTED --->
<CFIF Attributes.ForceWidth1 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att ributes.Fo rceWidthCh ar, Attributes.ForceWidth1)#</ CFOUTPUT>< /CFIF>
<CFOUTPUT></SELECT></CFOUT PUT>
<CFELSE>
<!--- RADIO BOXES --->
<CFSET Counter = 0>
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display 1#"><INPUT TYPE="Radio" NAME="#Attributes.Name1#" VALUE="#Evaluate(Attribute s.Value1)# " <CFIF Evaluate(Attributes.Value1 ) is Attributes.Default1>CHECKE D</CFIF> onClick="#FunctionName#(#C ounter#)"> #Evaluate( Attributes .Display1) ##Attribut es.HTMLAft erEachRadi o1#<CFSET Counter = Counter + 1></CFOUTPUT>
</CFIF>
<!--- INSERT ANY REQUESTED HTML BETWEEN 1ST AND SECOND ITEMS --->
<CFOUTPUT>#Attributes.HTML After1#</C FOUTPUT>
<!--- OUTPUT SECOND SELECT BOX --->
<CFOUTPUT><SELECT NAME="#Attributes.Name2#" SIZE="#Attributes.Size2#" onChange="#FunctionName2#( this.selec tedIndex)" <CFIF Attributes.Width2 is not "">STYLE="width:#Attribute s.Width2#" </CFIF>></ CFOUTPUT>
<!--- SPECIAL FIRST ITEM, IF REQUESTED --->
<CFIF Attributes.EmptyText2 is not ""><CFOUTPUT><OPTION VALUE="">#Attributes.Empty Text2#</CF OUTPUT></C FIF>
<!--- GENERATE REMAINING ITEMS FROM QUERY --->
<!--- WE ONLY NEED TO OUTPUT THE CHOICES FOR THE FIRST GROUP --->
<!--- <CFSET FirstGroup = Evaluate("MyQuery.#Attribu tes.Value1 #[1]")> --->
<CFSET FirstGroup = Attributes.Default1>
<CFSET CurrentGroup2 = "">
<CFIF Attributes.EmptyText1 is "">
<CFLOOP QUERY="MyQuery">
<CFIF Evaluate("MyQuery.#Attribu tes.Value1 #") is Variables.FirstGroup>
<CFSET ThisValue = Evaluate("MyQuery.#Attribu tes.Value2 #")>
<CFIF Variables.ThisValue is not Variables.CurrentGroup2>
<CFOUTPUT><OPTION VALUE="#Variables.ThisValu e#" <CFIF Variables.ThisValue is Attributes.Default2>SELECT ED</CFIF>> #Evaluate( "MyQuery.# Attributes .Display2# ")#</CFOUT PUT>
<CFSET CurrentGroup2 = Evaluate("MyQuery.#Attribu tes.Value2 #")>
</CFIF>
<!--- <CFELSE>
<CFBREAK> --->
</CFIF>
</CFLOOP>
</CFIF>
<!--- "FORCE WIDTH" OPTION AT BOTTOM, IF REQUESTED --->
<CFIF Attributes.ForceWidth2 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att ributes.Fo rceWidthCh ar, Attributes.ForceWidth2)#</ CFOUTPUT>< /CFIF>
<CFIF Attributes.ExtraOptions2 is not ""><CFLOOP INDEX="This" FROM="1" TO="#Attributes.ExtraOptio ns2#"><CFO UTPUT><OPT ION VALUE=""></CFOUTPUT></CFLO OP></CFIF>
<CFOUTPUT></SELECT></CFOUT PUT>
<!--- INSERT ANY REQUESTED HTML BETWEEN 2ND AND 3RD ITEMS --->
<CFOUTPUT>#Attributes.HTML After2#</C FOUTPUT>
<!--- OUTPUT THIRD SELECT BOX --->
<CFOUTPUT><SELECT NAME="#Attributes.Name3#" SIZE="#Attributes.Size3#" <CFIF Attributes.Multiple3 is "Yes">MULTIPLE </CFIF><CFIF Attributes.Width3 is not "">STYLE="width:#Attribute s.Width3#" </CFIF><CF IF Attributes.OnChange is not ""> OnChange="#Attributes.OnCh ange#"</CF IF>></CFOU TPUT>
<CFSET FirstGroup = Attributes.Default1>
<CFIF Attributes.EmptyText3 is "">
<CFLOOP QUERY="MyQuery">
<CFIF Evaluate("MyQuery.#Attribu tes.Value1 #") is Variables.FirstGroup>
<CFSET Hack = Evaluate("MyQuery.#Attribu tes.Value2 #")>
<CFSET ThisValue = Evaluate("MyQuery.#Attribu tes.Value3 #")>
<CFPARAM NAME="Variables.FirstGroup 2" DEFAULT="#Variables.Hack#" >
<CFIF Evaluate("MyQuery.#Attribu tes.Value2 #") is Variables.FirstGroup2>
<CFOUTPUT><OPTION VALUE="#Variables.ThisValu e#" <CFIF Variables.ThisValue is Attributes.Default3>SELECT ED</CFIF>> #Evaluate( "MyQuery.# Attributes .Display3# ")#</CFOUT PUT>
</CFIF>
</CFIF>
</CFLOOP>
</CFIF>
<CFIF Attributes.ForceWidth3 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att ributes.Fo rceWidthCh ar, Attributes.ForceWidth3)#</ CFOUTPUT>< /CFIF>
<CFIF Attributes.ExtraOptions3 is not ""><CFLOOP INDEX="This" FROM="1" TO="#Attributes.ExtraOptio ns3#"><CFO UTPUT><OPT ION VALUE=""></CFOUTPUT></CFLO OP></CFIF>
<CFOUTPUT></SELECT></CFOUT PUT>
<!--- REMOVE THIS AND FIRST LINE IF NOT USING CF3.1 OR LATER --->
<CFSETTING ENABLECFOUTPUTONLY="NO">
<CFSETTING ENABLECFOUTPUTONLY="YES">
<!--- TAG PARAMETERS --->
<CFPARAM NAME="Attributes.Query">
<CFPARAM NAME="Attributes.Type1" DEFAULT="Select">
<CFPARAM NAME="Attributes.HTMLAfter
<CFPARAM NAME="Attributes.Name1" DEFAULT="TwoSelectsRelated
<CFPARAM NAME="Attributes.Name2" DEFAULT="TwoSelectsRelated
<CFPARAM NAME="Attributes.Name3" DEFAULT="TwoSelectsRelated
<CFPARAM NAME="Attributes.Value1">
<CFPARAM NAME="Attributes.Value2">
<CFPARAM NAME="Attributes.Value3">
<CFPARAM NAME="Attributes.Display1"
<CFPARAM NAME="Attributes.Display2"
<CFPARAM NAME="Attributes.Display2"
<CFPARAM NAME="Attributes.Default1"
<CFPARAM NAME="Attributes.Default2"
<CFPARAM NAME="Attributes.Default3"
<CFPARAM NAME="Attributes.Multiple3
<CFPARAM NAME="Attributes.Size1" DEFAULT="1">
<CFPARAM NAME="Attributes.Size2" DEFAULT="1">
<CFPARAM NAME="Attributes.Size3" DEFAULT="1">
<CFPARAM NAME="Attributes.ExtraOpti
<CFPARAM NAME="Attributes.ExtraOpti
<CFPARAM NAME="Attributes.Width1" DEFAULT="">
<CFPARAM NAME="Attributes.Width2" DEFAULT="">
<CFPARAM NAME="Attributes.Width3" DEFAULT="">
<CFPARAM NAME="Attributes.ForceWidt
<CFPARAM NAME="Attributes.ForceWidt
<CFPARAM NAME="Attributes.ForceWidt
<CFPARAM NAME="Attributes.ForceWidt
<CFPARAM NAME="Attributes.EmptyText
<CFPARAM NAME="Attributes.EmptyText
<CFPARAM NAME="Attributes.EmptyText
<CFPARAM NAME="Attributes.Message1"
<CFPARAM NAME="Attributes.Message2"
<CFPARAM NAME="Attributes.Message3"
<CFPARAM NAME="Attributes.FormName"
<CFPARAM NAME="Attributes.HTMLAfter
<CFPARAM NAME="Attributes.HTMLAfter
<CFPARAM NAME="Attributes.OnChange"
<CFPARAM NAME="Attributes.AutoSelec
<CFIF Attributes.Type1 is "Radio">
<CFSET Attributes.EmptyText1 = "">
<CFSET Attributes.ForceWidth1 = "">
</CFIF>
<CFSET FunctionName = ReplaceList(Attributes.For
<CFSET FunctionName2 = ReplaceList(Attributes.For
<!--- "MAGIC" SHORTCUTS FOR THE ONCHANGE HANDLER --->
<CFIF Attributes.OnChange is "Jump!">
<CFSET Attributes.OnChange = "document.location = this.options[selectedIndex
<CFELSEIF Attributes.OnChange is "Submit!">
<CFSET Attributes.OnChange = "this.form.submit();">
</CFIF>
<!--- USE PASSED QUERY WITHIN THIS CODE AS "MyQuery" --->
<CFSET MyQuery = Evaluate("Caller.#Attribut
<!--- BEGIN JAVASCRIPTING --->
<CFOUTPUT>
<SCRIPT LANGUAGE="JavaScript1.1">
// javascript code generated by the CF_TwoSelectsRelated Cold Fusion tag (Nate Weiss, 4/98)
// portions adapted from Nick Heinle's code at http://webreference.com/javascript/960902/select_boxes.html
var maxlength = 10;
OneA = new Array;
var trueLength = OneA.length;
var lst = OneA.length;
var Trak = 0;
function require_#Attributes.Name1#
with (document.#Attributes.Form
RetVal = true;
if (Trak == -1) RetVal = false;
<CFIF Attributes.Type1 is "Select">
else RetVal = !(options[Trak].value == '');
<CFELSEIF Attributes.Type1 is "Radio">
else { if (document.#Attributes.Form
</CFIF>
if (!RetVal) alert('#Attributes.Message
return RetVal;
}
}
function require_#Attributes.Name2#
with (document.#Attributes.Form
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v
if (!RetVal) alert('#Attributes.Message
return eval(RetVal);
return RetVal;
}
}
function require_#Attributes.Name3#
with (document.#Attributes.Form
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v
if (!RetVal) alert('#Attributes.Message
return RetVal
}
}
function require_#Attributes.Name1#
return ((require_#Attributes.Name
}
function require_#Attributes.Name2#
return ((require_#Attributes.Name
}
function require_#Attributes.Name1#
return ((require_#Attributes.Name
}
function #FunctionName#(menuNum) {
OneA.length = 0;
if (menuNum == null) return;
Trak = menuNum;
<!--- ignore if a blank item gets clicked --->
<CFIF Attributes.Type1 is "Select">
if (document.#Attributes.Form
if (document.#Attributes.Form
</CFIF>
</CFOUTPUT>
<!--- COUNTER VARIABLE WILL HOLD NUMBER OF GROUPS (OPTIONS IN FIRST SELECT) --->
<CFSET Counter = IIF(Attributes.EmptyText1 is not "", 1, 0)>
<!--- CREATE AN "IF" STATEMENT THAT COVERS EACH ITEM IN THE FIRST SELECT BOX --->
<!--- WITHIN THE "IF" STATMENT, PRE-POPULATE ARRAY WITH CORRESPONDING ITEMS FOR SECOND SELECT --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display
if (menuNum == #Counter#) {
NewOpt = new Array;
NewVal = new Array;
<CFSET Counter2 = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFIF Attributes.EmptyText2 is not ""><CFOUTPUT>NewOpt[0] = new Option("#Attributes.EmptyT
<CFOUTPUT GROUP="#Attributes.Display
} <CFSET Counter = Counter + 1>
</CFOUTPUT>
<!--- finish up the ChangeMenu() function --->
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormN
for (i = lst; i > 0; i--) {
document.#Attributes.FormN
}
for (i = 0; i < tot; i++) {
document.#Attributes.FormN
}
<!--- <CFIF Attributes.AutoSelectFirst
document.#Attributes.FormN
<!--- </CFIF> --->
#FunctionName2#(0);
}
</CFOUTPUT>
<!--- ALLOW FOR AUTO-SIZING "SHORTCUT" OF SELECT BOXES --->
<CFIF Attributes.Size1 is "Auto">
<!--- MAKE THE FIRST SELECT BE BIG ENOUGH FOR ALL OF ITS OPTIONS --->
<CFSET Attributes.Size1 = Counter>
</CFIF>
<CFIF Attributes.Size2 is "Auto">
<!--- MAKE THE SECOND SELECT BE THE SAME SIZE AS THE FIRST --->
<CFSET Attributes.Size2 = Attributes.Size1>
</CFIF>
<CFIF Attributes.Size3 is "Auto">
<!--- MAKE THE SECOND SELECT BE THE SAME SIZE AS THE FIRST --->
<CFSET Attributes.Size3 = Attributes.Size1>
</CFIF>
<CFOUTPUT>
function #FunctionName2#() {
OneA.length = 0;
menuNum = Trak;
//menuNum = document.#Attributes.FormN
menuNum2 = document.#Attributes.FormN
if (menuNum == -1) return;
if (menuNum2 == null) return;
<!--- ignore if a the blank item gets clicked --->
if (document.#Attributes.Form
</CFOUTPUT>
<!--- COUNTER VARIABLE WILL HOLD NUMBER OF GROUPS (OPTIONS IN FIRST SELECT) --->
<CFSET Counter1 = 0>
<!--- CREATE AN "IF" STATEMENT THAT COVERS EACH ITEM IN THE FIRST SELECT BOX --->
<!--- WITHIN THE "IF" STATMENT, PRE-POPULATE ARRAY WITH CORRESPONDING ITEMS FOR SECOND SELECT --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display
if (menuNum == #Counter1#) {
<CFSET Counter = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFOUTPUT GROUP="#Attributes.Display
if (menuNum2 == #Counter#) {
NewOpt = new Array;
NewVal = new Array;
<CFSET Counter2 = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFIF Attributes.EmptyText3 is not "">NewOpt[0] = new Option("#Attributes.EmptyT
<CFOUTPUT>
NewOpt[#Counter2#] = new Option("#Evaluate(Attribut
NewOpt[#Counter2#].value = '#Evaluate(Attributes.Valu
<CFSET Counter2 = Counter2 + 1>
</CFOUTPUT>
} <CFSET Counter = Counter + 1>
</CFOUTPUT>
} <CFSET Counter1 = Counter1 + 1>
</CFOUTPUT>
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormN
for (i = lst; i > 0; i--) {
document.#Attributes.FormN
}
for (i = 0; i < tot; i++) {
document.#Attributes.FormN
}
<CFIF Attributes.AutoSelectFirst
document.#Attributes.FormN
</CFIF>
}
</SCRIPT>
</CFOUTPUT>
<!--- DONE WITH JAVASCRIPTING. NOW WE JUST HAVE TO DISPLAY THE FORM ELEMENTS --->
<!--- OUTPUT FIRST FORM ELEMENT --->
<CFIF Attributes.Type1 is "Select">
<CFOUTPUT><SELECT NAME="#Attributes.Name1#" onChange="#FunctionName#(t
<!--- SPECIAL FIRST ITEM, IF REQUESTED --->
<CFIF Attributes.EmptyText1 is not ""><CFOUTPUT><OPTION VALUE="">#Attributes.Empty
<!--- GENERATE REMAINING ITEMS FROM QUERY --->
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display
<!--- "FORCE WIDTH" OPTION AT BOTTOM, IF REQUESTED --->
<CFIF Attributes.ForceWidth1 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att
<CFOUTPUT></SELECT></CFOUT
<CFELSE>
<!--- RADIO BOXES --->
<CFSET Counter = 0>
<CFOUTPUT QUERY="MyQuery" GROUP="#Attributes.Display
</CFIF>
<!--- INSERT ANY REQUESTED HTML BETWEEN 1ST AND SECOND ITEMS --->
<CFOUTPUT>#Attributes.HTML
<!--- OUTPUT SECOND SELECT BOX --->
<CFOUTPUT><SELECT NAME="#Attributes.Name2#" SIZE="#Attributes.Size2#" onChange="#FunctionName2#(
<!--- SPECIAL FIRST ITEM, IF REQUESTED --->
<CFIF Attributes.EmptyText2 is not ""><CFOUTPUT><OPTION VALUE="">#Attributes.Empty
<!--- GENERATE REMAINING ITEMS FROM QUERY --->
<!--- WE ONLY NEED TO OUTPUT THE CHOICES FOR THE FIRST GROUP --->
<!--- <CFSET FirstGroup = Evaluate("MyQuery.#Attribu
<CFSET FirstGroup = Attributes.Default1>
<CFSET CurrentGroup2 = "">
<CFIF Attributes.EmptyText1 is "">
<CFLOOP QUERY="MyQuery">
<CFIF Evaluate("MyQuery.#Attribu
<CFSET ThisValue = Evaluate("MyQuery.#Attribu
<CFIF Variables.ThisValue is not Variables.CurrentGroup2>
<CFOUTPUT><OPTION VALUE="#Variables.ThisValu
<CFSET CurrentGroup2 = Evaluate("MyQuery.#Attribu
</CFIF>
<!--- <CFELSE>
<CFBREAK> --->
</CFIF>
</CFLOOP>
</CFIF>
<!--- "FORCE WIDTH" OPTION AT BOTTOM, IF REQUESTED --->
<CFIF Attributes.ForceWidth2 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att
<CFIF Attributes.ExtraOptions2 is not ""><CFLOOP INDEX="This" FROM="1" TO="#Attributes.ExtraOptio
<CFOUTPUT></SELECT></CFOUT
<!--- INSERT ANY REQUESTED HTML BETWEEN 2ND AND 3RD ITEMS --->
<CFOUTPUT>#Attributes.HTML
<!--- OUTPUT THIRD SELECT BOX --->
<CFOUTPUT><SELECT NAME="#Attributes.Name3#" SIZE="#Attributes.Size3#" <CFIF Attributes.Multiple3 is "Yes">MULTIPLE </CFIF><CFIF Attributes.Width3 is not "">STYLE="width:#Attribute
<CFSET FirstGroup = Attributes.Default1>
<CFIF Attributes.EmptyText3 is "">
<CFLOOP QUERY="MyQuery">
<CFIF Evaluate("MyQuery.#Attribu
<CFSET Hack = Evaluate("MyQuery.#Attribu
<CFSET ThisValue = Evaluate("MyQuery.#Attribu
<CFPARAM NAME="Variables.FirstGroup
<CFIF Evaluate("MyQuery.#Attribu
<CFOUTPUT><OPTION VALUE="#Variables.ThisValu
</CFIF>
</CFIF>
</CFLOOP>
</CFIF>
<CFIF Attributes.ForceWidth3 is not ""><CFOUTPUT><OPTION VALUE="">#RepeatString(Att
<CFIF Attributes.ExtraOptions3 is not ""><CFLOOP INDEX="This" FROM="1" TO="#Attributes.ExtraOptio
<CFOUTPUT></SELECT></CFOUT
<!--- REMOVE THIS AND FIRST LINE IF NOT USING CF3.1 OR LATER --->
<CFSETTING ENABLECFOUTPUTONLY="NO">
ASKER
Above is the tag source code. In my first post is the tag implimentation and my query. Any ideas on why it is not working in it's original state and how I can extend the custom tag to be a quad select or more?
Thanks for you help.
Thanks for you help.
Sorry, I did not get the notification (or it was seen as spam) that you had posted
No ideas on why it is not working. Not worth my time to look into since it is more code than my example of writing the solution by hand.
As for how to extend the tag. SImply copy everywhere that has a 3 and and change to a 4
For example:
function require_#Attributes.Name3# () {
with (document.#Attributes.Form Name#.#Att ributes.Na me3#) {
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v alue == '');
if (!RetVal) alert('#Attributes.Message 3#');
return RetVal
}
}
So you expand by adding this:
function require_#Attributes.Name4# () {
with (document.#Attributes.Form Name#.#Att ributes.Na me4#) {
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v alue == '');
if (!RetVal) alert('#Attributes.Message 4#');
return RetVal
}
}
Do this throughout hte tag to extend to 4 options.
If you see a place that has a 3 with other numbers like here:
function require_#Attributes.Name2# And#Attrib utes.Name3 #() {
return ((require_#Attributes.Name 2#()) && (require_#Attributes.Name3 #()));
}
then change the 3 to a 4 and the 2 to a 3 in the copy like this:
function require_#Attributes.Name3# And#Attrib utes.Name4 #() {
return ((require_#Attributes.Name 3#()) && (require_#Attributes.Name4 #()));
}
No ideas on why it is not working. Not worth my time to look into since it is more code than my example of writing the solution by hand.
As for how to extend the tag. SImply copy everywhere that has a 3 and and change to a 4
For example:
function require_#Attributes.Name3#
with (document.#Attributes.Form
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v
if (!RetVal) alert('#Attributes.Message
return RetVal
}
}
So you expand by adding this:
function require_#Attributes.Name4#
with (document.#Attributes.Form
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].v
if (!RetVal) alert('#Attributes.Message
return RetVal
}
}
Do this throughout hte tag to extend to 4 options.
If you see a place that has a 3 with other numbers like here:
function require_#Attributes.Name2#
return ((require_#Attributes.Name
}
then change the 3 to a 4 and the 2 to a 3 in the copy like this:
function require_#Attributes.Name3#
return ((require_#Attributes.Name
}
ASKER
OK, then based on your originial example is this the correct way to impliment?
<!--- Query - Country/County/State --->
<cfquery name="rsCountry" datasource="#mm_DATASOURCE _dsn#">
SELECT tbl_countries.Country, tbl_postalCode.State, tbl_postalCode.StateCode, tbl_postalCode.City, tbl_postalCode.County
FROM tbl_countries
INNER JOIN tbl_postalCode
ON tbl_countries.CountryID = tbl_postalCode.CountryID
ORDER BY tbl_countries.CountryID
</cfquery>
<script type="text/javascript" language="JavaScript">
<!--
/* Dynamically populate State select box based on seleted Country */
// Create an array to hold State
var StateArray = new Array;
// Define a custom Javascript object type to represent a single State
function State(County, Country, State)
{
this.County = County;
this.Country = Country;
this.State = State;
}
<!--- For each State, append a new State object to the array of State --->
<cfoutput query="GetState">
StateArray[StateArray.leng th] = new State("#JSStringFormat(Use rname)#", "#JSStringFormat(Country)# ", "#JSStringFormat(State)#") ;
</cfoutput>
/* Fill the State select box based on the Country */
function fillState()
{
// Stop if there is no selected ParentID
if (document.AddIssue.Country .selectedI ndex == -1)
{
return;
}
var Country = document.AddIssue.Country. options[do cument.Add Issue.Coun try.select edIndex].v alue;
// Remove all options in the State select box
document.AddIssue.State.op tions.leng th = 0;
// For each item in the State array ...
for (var i = 0; i < StateArray.length; i++)
{
// If the State's Country is the same as the currently selected Country
if (StateArray[i].Country == Country)
{
// Put a new option in the State select box
document.AddIssue.State.op tions[docu ment.AddIs sue.State. options.le ngth] = new Option(StateArray[i].State , StateArray[i].County);
}
}
}
-->
</script>
<select name="CountryID" onChange="fillCountries()" style="width: 200px;">
<option value="">Select Country</option>
<cfoutput query="rsCountry">
<option value="#rsCountry.Country# ">#rsCount ry.Country #</option>
</cfoutput>
</select>
<select name="State" style="width: 200px;"></select>
<!--- Query - Country/County/State --->
<cfquery name="rsCountry" datasource="#mm_DATASOURCE
SELECT tbl_countries.Country, tbl_postalCode.State, tbl_postalCode.StateCode, tbl_postalCode.City, tbl_postalCode.County
FROM tbl_countries
INNER JOIN tbl_postalCode
ON tbl_countries.CountryID = tbl_postalCode.CountryID
ORDER BY tbl_countries.CountryID
</cfquery>
<script type="text/javascript" language="JavaScript">
<!--
/* Dynamically populate State select box based on seleted Country */
// Create an array to hold State
var StateArray = new Array;
// Define a custom Javascript object type to represent a single State
function State(County, Country, State)
{
this.County = County;
this.Country = Country;
this.State = State;
}
<!--- For each State, append a new State object to the array of State --->
<cfoutput query="GetState">
StateArray[StateArray.leng
</cfoutput>
/* Fill the State select box based on the Country */
function fillState()
{
// Stop if there is no selected ParentID
if (document.AddIssue.Country
{
return;
}
var Country = document.AddIssue.Country.
// Remove all options in the State select box
document.AddIssue.State.op
// For each item in the State array ...
for (var i = 0; i < StateArray.length; i++)
{
// If the State's Country is the same as the currently selected Country
if (StateArray[i].Country == Country)
{
// Put a new option in the State select box
document.AddIssue.State.op
}
}
}
-->
</script>
<select name="CountryID" onChange="fillCountries()"
<option value="">Select Country</option>
<cfoutput query="rsCountry">
<option value="#rsCountry.Country#
</cfoutput>
</select>
<select name="State" style="width: 200px;"></select>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is hand code for how to write a two selects related, that can be easily extended to a 4 selects related
https://www.experts-exchange.com/questions/20973970/Use-of-Arrays-with-CF-TwoSelectsRelated.html
Simply write a fill function i.e. fillBuyers for each sub select and attach the event like this:
<select name="DepartmentID" onChange="fillState()" style="width: 200px;">
<option value=""></option>
<option value="1">Unites States</option>
<option value="2">Canada</option>
<option value="3">Spain</option>
etc.. // or have thsi from a query too.
</select>
<select name="State" onChange="fillCounty()" style="width: 200px;"></select>
<select name="County" onChange="fillCity()" style="width: 200px;"></select>
<select name="City" style="width: 200px;"></select>