Professional Web Applications Themes

Passing CF Arrays to javascript - Macromedia ColdFusion

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 ...

  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. #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

  3. #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

Similar Threads

  1. Passing arrays to functions
    By Eric Kincl in forum PHP Development
    Replies: 1
    Last Post: November 19th, 09:13 PM
  2. Passing Arrays
    By David P. Jessup in forum ASP
    Replies: 3
    Last Post: September 30th, 07:42 PM
  3. Passing arrays through functions
    By Henry in forum ASP
    Replies: 3
    Last Post: September 15th, 02:44 PM
  4. Passing arrays to SP
    By Gary B in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 10th, 05:49 PM
  5. Passing arrays to a stored procedure
    By Aaron Bertrand - MVP in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 1st, 02:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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