Ask a Question related to Coldfusion Database Access, Design and Development.
-
LohneB #1
Accessing CF array data from withing JavaScript code
Good afternoon!
I'm having a problem where there is probably a very simple solution, but I'm
up against a very rigid time schedule, and I could use some help resolving this
issue. (I'm not a JavaScript expert for one thing!)
I have an application that consists of CF (ver 5) and imbedded Javascript for
form/data validation; dynamic loading of data in forms, etc. I have a CF query
that selects data from a MS SQL table that is needed to fill a number of fields
in a form that is created in JavaScript. I can create a CF array and get the
data I need loaded in the array (single dimension) just fine. The code below
shows the CF code and a sample of the data in the array. What I need to be able
to do is then access the data from within JavaScript code so that I can place
the individual elements in the form. I know that there is something very basic
that I'm missing here, but with all the other aspects of the application that
are consuming me, I can't seem to focus on the solution! Any help would, of
course, be greatly appreciated.
The CF code:
************************************************** *****
************************************************** *****
<cfquery name="test2x" dbtype="query">
SELECT contract,
job_cd,
st_hr,
stlabor,
fy,
fymon,
mon,
mon3
FROM test1x
WHERE mon3 = 'xxx'
ORDER BY contract,
job_cd,
fy
</cfquery>
<cfset CstArray1 = ArrayNew(1)>
<cfset Res1 = ArrayClear(CstArray1)>
<cfif test2x.recordcount>
<cfoutput query="test2x">
<cfset ThisItem=ArrayLen(CstArray1) +1>
<cfset CstArray1[ThisItem]=test2x.stlabor>
</cfoutput>
</cfif>
<cfloop index = "Order" from = "1" to = "#ArrayLen(CstArray1)#">
<cfoutput>CstArray1[#Order#] value is #CstArray1[Order]#</cfoutput><br>
</cfloop>
************************************************** *******
************************************************** *******
And a printout of the data:
************************************************** *******
************************************************** *******
CstArray1[1] value is 291.00
CstArray1[2] value is 3819.00
CstArray1[3] value is 754.00
CstArray1[4] value is 221.00
CstArray1[5] value is 4988.00
CstArray1[6] value is 3121.00
CstArray1[7] value is 2020.00
CstArray1[8] value is 3356.00
CstArray1[9] value is 14465.00
************************************************** *******
************************************************** *******
This is the correct data (in this example) that needs to be loaded in the
JavaScript form.
Thanks!
Bill
[email]lohneb@bellsouth.net[/email]
LohneB Guest
-
Accessing swf or javascript in different html
Hi, From my understanding, the swf instance can communicate with other swf instance through the LocalConnection class. Also, the flex application... -
How to view the code of a Javascript array
<script language="javascript" src="http://www.thefreedictionary.com/_/WoD/jsa.aspx"></script> sends me a Javascript array. How do I view the code... -
Accessing data from C# code-behind in the ItemDataBound Event
Hello: If I want to access a particular column of data that is bound to a datagrid from within the ItemDataBound Event, how would I do that? I... -
Accessing Dataset data from code ... how?
Hi experts! here's a xml example of what i've got in my DataSet : <year>2002</year> <directors> <director> <first_name>Faouzi</first_name>... -
Accessing elements in array ref of array references
Currently I'm comparing the first value of each of the array references (which are stored in an array reference $ref_ref) as follows: ... -
philh #2
Re: Accessing CF array data from withing JavaScript code
Hi Bill,
You have your value return just fine. Now you need to translate the output
into JS variable assignments.
Just for grins:
<cfset CstArray1 = ArrayNew(1)>
<cfset CstArray1[1]=291.00>
<cfset CstArray1[2]=3819.00>
<cfset CstArray1[3]=754.00>
<cfset CstArray1[4]=221.00>
<cfset CstArray1[5]=4988.00>
<cfset CstArray1[6]=3121.00>
<cfset CstArray1[7]=2020.00>
<cfset CstArray1[8]=3356.00>
<cfset CstArray1[9]=14655.00>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="Javascript1.2">
function fillval() {
<cfoutput>
var CstArray1 = new Array();
<cfloop index="thisval" from="1" to = "#evaluate(arraylen(CstArray1)-1)#">
CstArray1[#thisval#] = #CstArray1[thisval]#;
</cfloop>
</cfoutput>
alert(CstArray1[3]);
}
</script>
</head>
<body onload="fillval();">
</body>
</html>
HTH,
philh Guest
-
Dan Bracuk #3
Re: Accessing CF array data from withing JavaScript code
If you are using cf7, use the toscript function.
Dan Bracuk Guest
-
LohneB #4
Re: Accessing CF array data from withing JavaScript code
For reference, I'm using CF 5 - I should have included that information originally. Sorry about that.
LohneB Guest



Reply With Quote

