Passing CF Arrays to javascript

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Passing CF Arrays to javascript

    Hello,

    I have an 1 dimensional Coldfusion array that I need to access from Javascript.

    When a user selects an item out of a list box, a call is placed to a
    javascript function and the id value of the item selected is pass in.

    I need to take that id and access the appropriate element within my array.
    Once I have accessed the element whose index matches the passed in ID, I need
    to display the contect within the array to the user.

    If I am unclear please let me know. I am pretty desparate on this, I have
    been working on it for more than a day and can not seem to get it to work.

    Thanks so much in advance for any help given!!

    Dallas

    dxsmith99 Guest

  2. Similar Questions and Discussions

    1. Passing arrays of structs from C# web service to raw C++?
      I have a C# webservice that returns an array of struct data back to a calling client. It works fine when tested via the ASMX page; however, I...
    2. Passing arrays to functions
      OK, another quickie, How do I pass an array to a function? This is what I have, and the second function doesn't seem to be getting the array...
    3. Passing Arrays
      Good day folks. I'm probably overlooking the obvious, but asking for feedback none the less =) Can you pass a multidimensional array to a self...
    4. Passing arrays through functions
      Hi, I need to pass an array to a function, change it a little and return it to the main code. When i try it the webpage is displayed up until the...
    5. Passing arrays to SP
      I have a transaction with several steps that I need to accomplish. I'm trying to decide if I should manage that transaction from my vb.net program...
  3. #2

    Default Re: Passing CF Arrays to javascript

    You can't get it to work because CF is server side and Javascript is client
    side and they cannot talk to each other.

    What you might want to try is something like this:

    <script language="Javascript">
    var js_array = (#ArrayLen(cf_array)#);
    <cfloop index="i" from="1" to="#ArrayLen(cf_array)#">
    js_array[#i#] = #cf_array#;
    </cfloop>
    function your_function_here()
    {
    }
    </script>

    You need to create a java script copy of your array so that it exists on the
    client side and your javascript function can access it.

    JR


    jonwrob Guest

  4. #3

    Default Re: Passing CF Arrays to javascript

    Hi DX, You can use the CFWDDX tag specifically for this task. It will work
    like this: <cfwddx action='cfml2js' input='#yourArray#' output='outputVariable'
    toplevelvariable='newJavascript'> This will automatically generate the
    javascript necessarry to match your ColdFusion array. Simply output
    #outputVariable# in your Javascript code to expose the javascript.

    sillyworm Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139