[thelist] Coldfusion: getting javascript variables

.jeff jeff at members.evolt.org
Tue Jan 8 22:37:09 CST 2002


ted,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: ted serbinski
>
> > [...] you're unnecessarily using the eval() method all
> > over the place.
>
> It seems I thought I needed those to get it evaluate a
> variable + a string for a dynamic name. Guess not.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

you can think of practically everything in javascript as an associative
array.  that means you can use bracket notation if you a) don't know the
name of the key or a string and a variable if you only know part of the
name.

here's an example from your application:

eval('data["'+id+'Name"]')

you're already using bracket notation and unnecessarily making it more
complex by using the eval() method.  try this instead:

data[id + 'Name'];

the concatenation happens first, forming a string that is then used within
the square brackets to reference a key in the "data" associative array.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Hmmm, having trouble with this part. I was able to
> convert my arrays into a WDDX packet on the page,
> showing this fine. But when I send this via a form
> and output this data, I get no ouptut.
>
> This is my code I'm using for output:
>
> <cfoutput>
> <textarea name="packet" rows=8 cols=50>#Form.packet#</textarea>
> </cfoutput>
>
> <cfwddx action="wddx2cfml" input="#Form.packet#"
> output="deserializedCode">
> <cfloop list="#deserializedCode.ColumnList#" index="ThisField">
> <cfoutput>
> #ThisField#: #Evaluate("deserializedCode." & ThisField)# <br>
> </cfoutput>
> </cfloop>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

i see you use the Evaluate() function in cf as well, like you do in js.
think of queries as associative arrays (the columns are the keys) where each
record is an indexed array.  taking that into account, you can use bracket
notation instead of the Evaluate() function to get at any row/column value
you want.

deserialized[thisField][currentrow]

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> All this displays is #Form.packet# and all my other
> variables, without actually evaluating there values.
> Any ideas?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

what do you get if you just output the form field value to the screen?

<pre>
<cfoutput>
#form.packet#
</cfoutput>
</pre>

if it outputs the wddx packet, then your cf template is receiving it
properly.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Also, the structure layout that was mentioned, this is
> just the best way to save my data from above, if I get
> it to display right?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

it's one way.  how you do it is up to you.  the important thing is to keep
the looping and conditionals to a minimum.  what you were suggesting before
would have involved looping over the entire collection and ignoring things
that don't fit.  the way i suggested (while maybe not the very best) means
you only look at one collection and go from beginning to end.






More information about the thelist mailing list