Greetings all.
In this same vein (and by the way, the DepressedPress.com website appears to be
down), is there someone
available who can take the time to explain the how's and why's of how the
following code works: integration of javascript and cfml.
Thanks in advance,
Carol
>From Nate Weiss': ThreeSelectsRelated
// 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
<!--- 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.FormName#.#Attributes.Name1#)
{
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.FormName#.#Attributes.Name1#[Trak].value == '') RetVal =
false; else RetVal = true;}
</CFIF>
if (!RetVal) alert('#Attributes.Message1#');
return RetVal;
}
}
function require_#Attributes.Name2#()
{
with (document.#Attributes.FormName#.#Attributes.Name2#)
{
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].value == '');
if (!RetVal) alert('#Attributes.Message2#');
return eval(RetVal);
return RetVal;
}
}
function require_#Attributes.Name3#()
{
with (document.#Attributes.FormName#.#Attributes.Name3#)
{
RetVal = true;
if (selectedIndex == -1) RetVal = false;
else RetVal = !(options[selectedIndex].value == '');
if (!RetVal) alert('#Attributes.Message3#');
return RetVal
}
}
function require_#Attributes.Name1#And#Attributes.Name2#()
{
return ((require_#Attributes.Name1#()) &&
(require_#Attributes.Name2#()));
}
function require_#Attributes.Name2#And#Attributes.Name3#()
{
return ((require_#Attributes.Name2#()) && (require_#Attributes.Name3#()));
}
function
require_#Attributes.Name1#And#Attributes.Name2#And#Attributes.Name3#()
{
return ((require_#Attributes.Name1#And#Attributes.Name2#()) &&
(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.FormName#.#Attributes.Name1#.options[menuNum].value == '')
return;
if
(document.#Attributes.FormName#.#Attributes.Name1#.options[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.Display1#">
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.EmptyText2#");
NewOpt[0].value = '';
</CFOUTPUT>
</CFIF>
<CFOUTPUT GROUP="#Attributes.Display2#">
NewOpt[#Counter2#] = new Option("#Evaluate(Attributes.Display2)#");
NewOpt[#Counter2#].value = '#Evaluate(Attributes.Value2)#';
<CFSET Counter2 = Counter2 + 1>
</CFOUTPUT>
}
<CFSET Counter = Counter + 1>
</CFOUTPUT>
<!--- finish up the ChangeMenu() function --->
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormName#.#Attributes.Name2#.options.length;
for (i = lst; i > 0; i--)
{
document.#Attributes.FormName#.#Attributes.Name2#.options[i] = null;
}
for (i = 0; i < tot; i++)
{
document.#Attributes.FormName#.#Attributes.Name2#.options[i] =
NewOpt[i];
}
<!--- <CFIF Attributes.AutoSelectFirst is "Yes"> --->
document.#Attributes.FormName#.#Attributes.Name2#.options[0].selecte
d = true;
<!--- </CFIF> --->
#FunctionName2#(0);
} //function #FunctionName#(menuNum)
</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.FormName#.#Attributes.Name1#.selectedIndex;
menuNum2 =
document.#Attributes.FormName#.#Attributes.Name2#.selectedIndex;
if (menuNum == -1) return;
if (menuNum2 == null) return;
<!--- ignore if a the blank item gets clicked --->
if
(document.#Attributes.FormName#.#Attributes.Name2#.options[menuNum2].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.Display1#">
if (menuNum == #Counter1#)
{
<CFSET Counter = IIF(Attributes.EmptyText2 is not "", 1, 0)>
<CFOUTPUT GROUP="#Attributes.Display2#">
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.EmptyText3#"); NewOpt[0].value = ''; </CFIF>
<CFOUTPUT>
NewOpt[#Counter2#] = new
Option("#Evaluate(Attributes.Display3)#");
NewOpt[#Counter2#].value = '#Evaluate(Attributes.Value3)#';
<CFSET Counter2 = Counter2 + 1>
</CFOUTPUT>
} <CFSET Counter = Counter + 1>
</CFOUTPUT>
}
<CFSET Counter1 = Counter1 + 1>
</CFOUTPUT>
<CFOUTPUT>
tot = NewOpt.length;
lst = document.#Attributes.FormName#.#Attributes.Name3#.options.length;
for (i = lst; i > 0; i--)
{
document.#Attributes.FormName#.#Attributes.Name3#.options[i] = null;
}
for (i = 0; i < tot; i++)
{
document.#Attributes.FormName#.#Attributes.Name3#.options[i] =
NewOpt[i];
}
<CFIF Attributes.AutoSelectFirst is "Yes">
document.#Attributes.FormName#.#Attributes.Name3#.options[0].selecte
d = true;
</CFIF>
}//function #FunctionName2#
</SCRIPT>
</CFOUTPUT>
Carol L. Bluestein
Senior Programmer
NYS Office of Real Property
518-486-6335
[EMAIL PROTECTED]
____________________Reply Separator____________________
Subject: RE: JavaScript use with ColdFusion Variables
Author: [EMAIL PROTECTED]
Date: 4/11/01 9:19 AM
Javascript = client side
coldfusion = server side
So you have to be... inventive...
http://www.vboston.com/DepressedPress/Content/ColdFusion/Essays/GIFAsPipe/In
dex.cfm
> -----Original Message-----
> From: Bruce, Rodney [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 11, 2001 5:07 PM
> To: CF-Talk
> Subject: JavaScript use with ColdFusion Variables
>
>
> Is there a way to directly set a CF Variable from javascript?
>
> Examples:
>
> This is a build in script with CF Studio which will display
> to screen, but
> does not assign the value to anything:
>
> <script language="JavaScript" type="text/javascript">
> <!--
> document.write("You are using " + navigator.appName + " " +
> navigator.appVersion);
> // -->
> </script>
>
> This is a script that will assign to a form text field, then
> the form has to
> be submitted to an action page for value to be used:
>
> <script language="JavaScript" type="text/javascript">
> document.formname.fieldname.value = (navigator.appName +' ' +
> navigator.appVersion);
> </script>
>
> Is there a way to assign the value to a variable for use on
> the same page,
> outside of the <script> tag?
>
>
> Thanks for your help
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists