Skip to main content
Inspiring
July 4, 2008
Question

CF Array and JavaScript

  • July 4, 2008
  • 21 replies
  • 2408 views
Is it possible to manipulate arrays created in coldfusion with JavaScript?
All I'm trying to do is update a count (array length) dynamically everytime something is added to the array. So I got the brilliant idea to add the data submitted using JS and do a dynamic count update at the same time. But what I get is the JS error saying the array is undefined.

Suggestions?
This topic has been closed for replies.

21 replies

Inspiring
July 4, 2008
variables, arrays, lists, structures created/declared in cf won't be identified in javascripts. Example below:

<cfset x = "some_value">
<cfoutput>
<script language="javascript">
<!--
alert(x);
//-->
</script>
</cfoutput>

The example above will throw an error since x in javascript(which is not defined in js) is not the same as the x in cf.
Instead, for the above code, you need to do this:

<cfset x = "some_value">
<cfoutput>
<script language="javascript">
<!--
alert("#x#"); <!--- notice the number/hash sign. this way, x will be displayed(note: x is still a cf variable and not a js var) --->
//-->
</script>
</cfoutput>

Anyway, what exactly are you trying to do? Can you attach a portion of your code?