473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem converting Coldfusion array variable to Javascript array variable

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 8764
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

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

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

Thanks for pointing that out.
Jun 18 '07 #4
improvcornartist
303 Expert 100+
I'm not familiar with CFWDDX, so I probably can't be of much help. Does the CF repositoryArray fill correctly? Does jsrepositoryArray need to be declared before the CFWDDX tag?
Jun 18 '07 #5
The CF repositoryArray is populating correctly. Regarding declaring jsrepositoryArray 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 jsrepositoryArray first and it still doesn't work.
Jun 19 '07 #6
improvcornartist
303 Expert 100+
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
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
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....
39
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)...
7
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...
45
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...
2
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...
0
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...
5
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...
8
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
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.