Debt Consolidation - Debt Consolidation - Debt Consolidation - Bad Credit Loans - Debt Consolidation

PDA

View Full Version : Bulding Object literal strings using javascript & asp


mukapen
Feb 10th 2007, 9:22 am
I am trying to create a javascript object using javascript variables but won't work. However it appears to work if i use asp variable!

I have 2 code snipnets:

data = "Contract1":["S1234", "62,615.266","7-Dec-2007"],
"Contract1":["S1234", "62,615.266","7-Dec-2007"]

if 'data' is an asp variable

<script>
var myData = {<%=data%>};
alert ('myData = ' + myData[0][1]);
</script>

works fine

However if 'data' is javascript variable

<script>
var myData = {data};
alert ('myData = ' + myData[0][1]);
</script>

doesn't work. What could be wrong somebody help!

giraph
Feb 10th 2007, 6:48 pm
The way you defined data is not valid for javascript.

mukapen
Feb 11th 2007, 9:59 pm
In problem statement above, variable 'data' holds the property-value pairs which are then used to create a javascript object. How else would i define it in javascript.

Please help

mukapen
Feb 11th 2007, 10:02 pm
In problem statement above, variable 'data' holds the property-value pairs which are then used to create a javascript object. How else would i define it in javascript.

Please help

giraph
Feb 11th 2007, 11:36 pm
You define a multidimension array in javascript like:


yourArray = new Array();
yourArray[0] = new Array();
yourArray[0][0] = "blah";


If i remember right.

mukapen
Feb 12th 2007, 5:05 am
Allow me to re-phrase my query,



I need to construct propert-value pair object in javascript using object literals.

The general format of the object literal is defined as:



var obj = {string:array};



If the propert-value pair is constructed in asp so that



var obj = {<%=property-valuepairstring%>} ;



works fine, however if property-valuepairstring is a javascript variable i.e.



var obj = {property-valuepairstring};



i encounter object expected error.



Please shed some light in the dilemma i find myself.