DBrown
asked on
please help with question in javascript area
Could someone try to help me with this question? I need to populate a javascript array with a query.
I am using CF also. I cannot use the cfscript tag for specific reasons.
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=javascript&qid=20183445
Thanks
Doug
I am using CF also. I cannot use the cfscript tag for specific reasons.
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=javascript&qid=20183445
Thanks
Doug
pkinetics solution works. It just looks better to do it this way:
<CFOUTPUT><SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
var myArray = new Array(#ValueList(MyQuery.S ome_Intege r_ID)#);
</SCRIPT></CFOUTPUT>
Is it an array of integers or strings?
<CFOUTPUT><SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
var myArray = new Array(#ValueList(MyQuery.S
</SCRIPT></CFOUTPUT>
Is it an array of integers or strings?
ASKER
It needs to be a multidimensional array like below. String values
var regionalOffices = new Array()
// Stuff main array entries with objects.
regionalOffices[0] = new officeRecord("New York", "Shirley Smith", 300000)
regionalOffices[1] = new officeRecord("Chicago", "Todd Gaston", 250000)
regionalOffices[2] = new officeRecord("Houston", "Leslie Jones", 350000)
regionalOffices[3] = new officeRecord("Portland", "Harold Zoot", 225000)
var regionalOffices = new Array()
// Stuff main array entries with objects.
regionalOffices[0] = new officeRecord("New York", "Shirley Smith", 300000)
regionalOffices[1] = new officeRecord("Chicago", "Todd Gaston", 250000)
regionalOffices[2] = new officeRecord("Houston", "Leslie Jones", 350000)
regionalOffices[3] = new officeRecord("Portland", "Harold Zoot", 225000)
I know my suggestion works. I have done it numerous times without a glitch. Matter of fact I cut it right out of a production piece of code.
ASKER
I appreciate it, but I would rellay like to have a few more suggestions. I honestly do not like the way wddx outputs it's array.
Doug
Doug
What specifically are you looking for?
My other suggestion will work as you requested in your other post.
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0
<cfoutput query="queryName">
arrMyArray[i] = new Array('#field1#', '#field2#', '#field3#')
//alert(arrMyArray[i]);
i++
</cfoutput>
</script>
If you want, you can also throw an alert statement in there so you can see the output as it is being added to the array.
My other suggestion will work as you requested in your other post.
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0
<cfoutput query="queryName">
arrMyArray[i] = new Array('#field1#', '#field2#', '#field3#')
//alert(arrMyArray[i]);
i++
</cfoutput>
</script>
If you want, you can also throw an alert statement in there so you can see the output as it is being added to the array.
ASKER
I tried your code. I get a error: missing ). Also this is the output I get. I do not get a index for the array. I copied your exact code and simply replaced the queryName and the coldfusion variable names
script language="javascript">
var arrMyArray = new Array();
var intIndex = 0
arrMyArray[i] = new Array('cpu', 'test-cpu1', 'This is the best out there big bad brudda')
i++
script language="javascript">
var arrMyArray = new Array();
var intIndex = 0
arrMyArray[i] = new Array('cpu', 'test-cpu1', 'This is the best out there big bad brudda')
i++
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0;
<cfoutput query="queryName">
arrMyArray[intIndex] = new Array('#field1#', '#field2#', '#field3#');
intIndex++;
</cfoutput>
</script>
try that... I copied too much right from the start. You can limit the output on the CFOUTPUT tag to just five records and that will give you a small dataset to work with, rather than looking at the whole thing.
Also makes it easier to track down javascript error messages.
var arrMyArray = new Array();
var intIndex = 0;
<cfoutput query="queryName">
arrMyArray[intIndex] = new Array('#field1#', '#field2#', '#field3#');
intIndex++;
</cfoutput>
</script>
try that... I copied too much right from the start. You can limit the output on the CFOUTPUT tag to just five records and that will give you a small dataset to work with, rather than looking at the whole thing.
Also makes it easier to track down javascript error messages.
ASKER
Strange. I still get the same result
Here is my code you gave.
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0;
<cfoutput query="getCompParts">
arrMyArray[intIndex] = new Array('#description#', '#partNum#', '#salePrice#');
intIndex++;
</cfoutput>
</script>
and the result
arrMyArray[intIndex] = new Array('This is the best out there big bad brudda', 'test-cpu1', '2000.0000');
intIndex++;
doug
Here is my code you gave.
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0;
<cfoutput query="getCompParts">
arrMyArray[intIndex] = new Array('#description#', '#partNum#', '#salePrice#');
intIndex++;
</cfoutput>
</script>
and the result
arrMyArray[intIndex] = new Array('This is the best out there big bad brudda', 'test-cpu1', '2000.0000');
intIndex++;
doug
I'm assuming your dataset contains more than 1 record. Otherwise it works fine.
Are you still getting a javascript error message? How many records are there in the dataset?
Does the array data get disjointed? ie text is scattered throughout the page? Usually that is caused by carrage returns in the description field. You might need to run a #replace(description, chr(13), '')# instead of #description#.
Are you still getting a javascript error message? How many records are there in the dataset?
Does the array data get disjointed? ie text is scattered throughout the page? Usually that is caused by carrage returns in the description field. You might need to run a #replace(description, chr(13), '')# instead of #description#.
DBrown,
How about calculating the price as the user changes the configuration? The solution I have in mind is simpler. You pass the values to Javascript variables using CF (while generating the page) and use Javascript to do the calculation. Let me know if this is a solution you would consider and I'll post a sample code.
How about calculating the price as the user changes the configuration? The solution I have in mind is simpler. You pass the values to Javascript variables using CF (while generating the page) and use Javascript to do the calculation. Let me know if this is a solution you would consider and I'll post a sample code.
ASKER
Yes I would consider that.
DB
DB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry so late.............
A not so elegant way to do it
<script language="javascript">
var arrMyArray = new Array();
var intIndex = 0
<cfoutput query="queryName">
arrMyArray[i] = new Array('#field1#', '#field2#'...)
i++
</cfoutput>
</script>