Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2007, 10:11 PM   PM User | #1
amol0010
New Coder

 
Join Date: Jul 2007
Posts: 61
Thanks: 10
Thanked 0 Times in 0 Posts
amol0010 is an unknown quantity at this point
Array of objects question !

I have a question regarding Javascript object arrays -

Suppose I have a global variable which is an object array


//Global variable Point Of Interest
var PointsOfInterest = new Array('lat','lng');



I also have a table named markers in my MySQL database, the script phpsqlajax_genxml.php reads the database, outputs it into XML.



//-------------Read the markers/Points of interest from the database----------------

GDownloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");

for (var i = 0; i < markers.length; i++) {


PointsOfInterest[i] = (parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")) );


}
});


I want to be able to assign the object of "markers" to PointsOfInterest,

e.g. if

markers[o].lat = 56.4113 and markers[0].lng = -2.9145

then I should be able to assign,

PointsOfInterest[0] = markers[0];

and then later be able to call PointsOfInterest[0].lat and PointsOfInterest[0].lng so that they return values 56.4113 and -2.9145 respectively

Any idea on how to do this ?


Thanks,
Amol
amol0010 is offline   Reply With Quote
Old 08-23-2007, 09:06 AM   PM User | #2
mcjwb
Regular Coder

 
Join Date: Jul 2007
Location: UK
Posts: 223
Thanks: 0
Thanked 14 Times in 14 Posts
mcjwb is an unknown quantity at this point
Quote:
I want to be able to assign the object of "markers" to PointsOfInterest,

e.g. if

markers[o].lat = 56.4113 and markers[0].lng = -2.9145

then I should be able to assign,

PointsOfInterest[0] = markers[0];

and then later be able to call PointsOfInterest[0].lat and PointsOfInterest[0].lng so that they return values 56.4113 and -2.9145 respectively
markers[0] will be an xml element, so while you can assign markers[0] to PointsOfInterest[0] you would have to access the lat and long attributes via the getAttribute("lat") method.

Did my answer to your older post not help? Do you need a further explanation?
__________________
Javascript Debugging Tools:
IE Script Debugger | IE Developer Toolbar | Fiddler || FF Firebug | FF Web Developer
mcjwb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 AM.


Advertisement
Log in to turn off these ads.