473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem converting Coldfusion array variable to Javascript array variable

4 New Member
I am coding in Coldfusion MX7 and using Javascript for some of the functionality. The basic functionality I'm coding is, based on a value the user chooses from a dropdown box, I populate address fields with the associated data. I am using the onChange attribute of the dropdown box for the call to a Javascript function. I prepopulate a Coldfusion array with the address data and am using cfwddx to convert the Coldfusion array to a Javascript array. My problem is that the conversion doesn't seem to be working. The length of the Javascript array is 0, when it should be 3. Any suggestions?

Here's the relevant code:

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. function setRepositoryLocation(formValue)
  3. {
  4.      <CFWDDX action="CFML2JS" input="#repositoryArray#" toplevelvariable="jsrepositoryArray">
  5.      alert(jsrepositoryArray.length);
  6.      for(i=0; i<jsrepositoryArray.length; i++)
  7.      {
  8.     if (jsrepositoryArray[i][0] == formValue)
  9.     {
  10.                       document.frmInputSources.txtAddress1.value = jsrepositoryArray[i][1];
  11.             document.frmInputSources.txtAddress2.value = jsrepositoryArray[i][2];
  12.          document.frmInputSources.txtIDCountry.value = jsrepositoryArray[i][3];
  13.          document.frmInputSources.txtIDState_Province.value = jsrepositoryArray[i][4];
  14.          document.frmInputSources.txtCity.value = jsrepositoryArray[i][5];         document.frmInputSources.txtPostal_Code.value = jsrepositoryArray[i][6];
  15.     }
  16.      }
  17. }
  18. </script>
  19. </head>
  20. <body>
  21.  
  22. <CFSET arrIndex = 1>
  23. <CFSET repositoryArray = ArrayNew(2)>
  24. <CFOUTPUT QUERY="retSourceRepositories">
  25.     <CFSET repositoryArray[arrIndex][1] = #idSource_Repository#>
  26.     <CFSET repositoryArray[arrIndex][2] = #Address1#>
  27.     <CFSET repositoryArray[arrIndex][3] = #Address2#>
  28.     <CFSET repositoryArray[arrIndex][4] = #Country#>
  29.     <CFSET repositoryArray[arrIndex][5] = #State_Province#>
  30.     <CFSET repositoryArray[arrIndex][6] = #City#>
  31.     <CFSET repositoryArray[arrIndex][7] = #Postal_Code#>
  32.     <CFSET arrIndex = #arrIndex# + 1>
  33. </CFOUTPUT>
  34.  
  35. <select style="float:left" name="txtIDSource_Repository" id="" class=""
  36.     onchange="javascript:if(this.value != 0) {setRepositoryLocation(this.value);}">
  37. .
  38. .
  39. .
  40. </select>
  41. </body>
Jun 17 '07 #1
7 8772
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

This is more suitable for the Coldfusion forum to which I've moved this thread.
Jun 18 '07 #2
improvcornartist
303 Recognized Expert Contributor
The first thing I notice in your code is that you have an </script> tag but no beginning script tag.
Jun 18 '07 #3
kmitchell00
4 New Member
Oops. Copy-and-paste mistake. Here's the beginning <script> tag:

<script language="javas cript" type="text/javascript">

Thanks for pointing that out.
Jun 18 '07 #4
improvcornartist
303 Recognized Expert Contributor
I'm not familiar with CFWDDX, so I probably can't be of much help. Does the CF repositoryArray fill correctly? Does jsrepositoryArr ay need to be declared before the CFWDDX tag?
Jun 18 '07 #5
kmitchell00
4 New Member
The CF repositoryArray is populating correctly. Regarding declaring jsrepositoryArr ay prior to the CFWDDX statement, The examples I've seen of CFWDDX didn't show that prior declaring of variables was required. I tried declaring the variable jsrepositoryArr ay first and it still doesn't work.
Jun 19 '07 #6
improvcornartist
303 Recognized Expert Contributor
One thing to try may be adding a src to the javascript tag:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript" src="/CFIDE/scripts/wddx.js">
  2. </script>
The wddx.js file might be required for the cfwddx tag. If that is no help, you might be able to use the output attribute with the cfwddx tag, which should be able to tell you the output of the operation.
Jun 19 '07 #7
kmitchell00
4 New Member
Thanks for the suggestion. I did add that line. I also found my other problem. I shouldn't have put the <cfwddx tag within the javascript, but after i populated the coldfusion array.

Here are the code lines I put after populating the repositoryArray :

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
  2.  
  3. <CFWDDX action="CFML2JS" input="#repositoryArray#" toplevelvariable="jsrepositoryArray" output="jsArray">
  4.  
  5. <CFOUTPUT>#jsArray#</CFOUTPUT>
  6.  
  7. </SCRIPT>
  8.  
Thanks for all the suggestions.
Jun 24 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3916
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
39
19565
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
7
1760
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the problem is with this code, it just simply won't work properly. Some of the functions aren't done, but the main one gives me a Not a Number message in the...
45
4780
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4,...
2
2192
by: am_pcguy | last post by:
I have a web based application for my company. We use Coldfusion, I wanted to see if I could use Javascript to make the page a bit more dynamic. Right now I use the command: <cfhttp URL="http://server:port" method="get" Timeout="20" charset="UTF-8"> <cfhttpparam name="var" type="CGI" value="command I send"> this connects to an...
0
2015
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual Studio 2005). The problem occurred when I trying to opening and reading file: ============= C++ ============= void LoadSourceFile(char *...
5
6493
by: subhodey | last post by:
Hello, I have a ColdFusion online application that has a page having 2 textboxes. Corresponding to these 2 textboxes I have a Custom tag in coldfusion where the textbox is defined by <input type=text .....>. In the onChange event a coldfusion attribute is called (like, onChange="#attributes.onChange#"). Now in the cold fusion page the 2...
8
13595
by: jesmi | last post by:
my code is: addRecord.cfm <cfinclude template="head.cfm"> <p> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td> <div align="center">
2
3140
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early...
0
7406
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7660
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7761
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3457
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.