Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing ColdFusion Array into Javascript

Status
Not open for further replies.

dxsmith

Programmer
Mar 17, 2005
2
CA
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
 
I managed to figure it out. And yes, attributes.param_third_listbox_array is my CF array. Here is the code that I used:

function DisplayMembers(l_selected_member_id)
{
var oForm=document.#attributes.param_form#
var oMembers=oForm.DisplayedFields

var arrMembers = new Array();
<cfloop index="i" from="1" to="#ArrayLen(attributes.param_third_listbox_array)#">

if (#attributes.param_third_listbox_array[1]# == l_selected_member_id)
{
<cfloop from="1" to="#listlen(attributes.param_third_listbox_array[2])#" index="l">
<cfset j = l - 1>
arrMembers[#j#] = "#listgetat(attributes.param_third_listbox_array[2], l)#";
</cfloop>
}

</cfloop>

for (i=0; i<oMembers.options.length; i++)
{
oMembers.options[1] = null;
}

for (i=0; i<arrMembers.length; i++)
{
oMembers = new Option(arrMembers,arrMembers);
}

}


Thanks again!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top