> I tried using <CFWDDX> to pass CF variable into Javascript. However
> I realised that I can only have one variable, is there any ways
> that I can pass two CF variables into JS function?
>
> Below are my codes:
>
> <CFWDDX INPUT="#property_count#" OUTPUT="MyWDDXPacket"
> ACTION="CFML2WDDX">
> <CFWDDX INPUT="#MyWDDXPacket#" OUTPUT="DynamicJSCode" ACTION="WDDX2JS"
> TOPLEVELVARIABLE="MyJSVariable">

Yes, you can pass as many variables as you want from CF to JavaScript. It's
important to remember that when you "pass" variables from CF to JavaScript,
what you're really doing is generating JavaScript code with CF. That
JavaScript code will be executed on the client. So, here's an example of
passing variables from CF to JavaScript:

<cfset var1 = "foo">
<cfset var2 = "bar">

<html>
<head>
<title>Passing CF vars to JS</title>
<script language="JavaScript">
<cfoutput>
var myjsvar1 = '#Variables.var1#';
var myjsvar2 = '#Variables.var2#';
</cfoutput>
</script>
</head> ...

As you can see, you don't need CFWDDX to do this. You might want to use
CFWDDX, though, if you want to pass a lot of data at once, and that data can
be described within a single complex data object. A query object is a good
example. The following code will take a query object, and build a
client-side "recordset" in JavaScript:

<cfquery name="myquery" ...>
        SELECT ...
</cfquery>

<html>
<head>
<title>Passing CF vars to JS</title>
<script language="JavaScript" src="/cfide/scripts/wddx.js"></script> <!--
needed for WDDX client-side functions -->
<script language="JavaScript">
<cfwddx action="cfml2js" input="#myquery#" toplevelvariable="myjsrecordset">
</script>

There are a couple of things to note about the above code sample. First,
there's a reference to an external JavaScript library, wddx.js, which is
needed to manipulate this data on the client. Second, there's the CFWDDX tag
itself. It takes the query as the input attribute, and creates a JavaScript
object called myjsrecordset. This object will contain arrays which represent
the columns of data. Within the CFWDDX tag above, there's no OUTPUT
attribute, so this tag will write directly to the page, generating the
JavaScript code to represent the recordset.

This should be enough to get you started. You can deal with any single data
object this way using CFWDDX; that object may be a container for other data,
or it may be a simple variable.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

------------------------------------------------------------------------------
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