473,473 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Objects

Hello All:

I am trying to figure out how to use objects properties in my code so
when the page loads All my properties are in object where I can use
elsewhere in my page.

I am new to JavaScrip Objects so any help would be appreciated.

Thanks
SPS

function onload()
{
var id = 25;
var previewProperties = new PreviewProperties();
previewProperties = tripPreviewProperties(id);

//Need to Display lat,lon & scale
//alert(previewProperties.lat); This Does Not Work

}

//Preview Properties Object
function PreviewProperties(lat,lon) {
this.lat = lat;
this.lon = lon;
this.scale =4;
}
function tripPreviewProperties(id)
{

AjaxCommon.GoogleMapsTripPreviewProperties(id,trip PreviewProperties_callback);
}
function tripPreviewProperties_callback(res)
{
properties = new PreviewProperties(res.value.Lat,res.value.Lon);

// Corect Properties are Displayed
alert(properties.lat + "\n" + properties.lon );

return properties;
}

Aug 3 '05 #1
2 1284
st********@gmail.com wrote:
Hello All:

I am trying to figure out how to use objects properties in my code so
when the page loads All my properties are in object where I can use
elsewhere in my page.

I am new to JavaScrip Objects so any help would be appreciated.

[...]

The first part of any design is knowing the requirements. What are
the objects for and what data will they hold?

For example, below is a simple object to hold way points and some code
to present the values for each point.

<script type="text/javascript">

var wayPoint = {};
wayPoint.City_1 = { lat:150.0, lon:27.2, scale: 5 };
wayPoint.City_2 = { lat:151.2, lon:27.5, scale: 5 };
wayPoint.City_3 = { lat:153.4, lon:27.6, scale: 5 };

function showWaypoint( el ){
var wp = el[el.selectedIndex].value;
var ref = wayPoint[ wp ];
if ( '' != ref ) {
alert( wp
+ '\nLatitude: ' + ref.lat
+ '\nLongitude: ' + ref.lon
+ '\nScale: ' + ref.scale
);
}
}
</script>

<select onchange="showWaypoint(this);">
<option value="City_1">City 1</option>
<option value="City_2">City 2</option>
<option value="City_3">City 3</option>
</select>

or done slightly differently:

var wayPoint = {
City_1 :{ lat:150.0, lon:27.2, scale: 5 },
City_2 :{ lat:151.2, lon:27.5, scale: 5 },
City_3 :{ lat:153.4, lon:27.6, scale: 5 }
};

Or you could give wayPoints some methods to add way points and then
feed it data from an array. But it seems pointless to create an array
just to feed to an object when you could load the object with the data
in the first place and not bother with the method.

But if you want to modify the object's data it may be better if the
methods belong to the object.

As I said, it all depends on what you want this thing to do.

--
Rob
Aug 3 '05 #2
RobG wrote:
[...]
For example, below is a simple object to hold way points and some code
to present the values for each point.

<script type="text/javascript">

var wayPoint = {};
wayPoint.City_1 = { lat:150.0, lon:27.2, scale: 5 };
wayPoint.City_2 = { lat:151.2, lon:27.5, scale: 5 };
wayPoint.City_3 = { lat:153.4, lon:27.6, scale: 5 };

function showWaypoint( el ){
var wp = el[el.selectedIndex].value;
var ref = wayPoint[ wp ];
if ( '' != ref ) {


Sorry, that was not meant to be there (it's a pretty silly test)

var wp = el[el.selectedIndex].value;
var ref;
if ( '' != wp && (ref = wayPoint[wp]) ) {
and the first option should have no value:

<select onchange="showWaypoint(this);">
<option>Select a city</option>
...
[...]
--
Rob
Aug 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
5
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
2
by: KoliPoki | last post by:
Greetings. I'm having a little trouble with a query. The idea is simple I need to display a list of recently unique visited URLs and the last time I visited. I have 2 table one stores the...
4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
1
by: aredo3604gif | last post by:
On Sun, 10 Apr 2005 19:46:32 GMT, aredo3604gif@yahoo.com wrote: >The user can dynamically enter and change the rule connection between >objects. The rule is a "<" and so given two objects: >a <...
2
by: duncanblacksmithmath | last post by:
I know a lot of you have seen this before but I have worked on the program and have gotten it to work thus far but I need help getting these two functions to work and implementing them. Here is...
4
by: Tarun Mistry | last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies to both (apologies if it breaks some group rules). I am making a web app in asp.net using c#. This is the first fully OO...
5
by: =?Utf-8?B?QkY=?= | last post by:
I want to improve the response time of my application. I have 3 options: 1. Run both ASPX pages and our business objects on web server and use web farm technology. 2. Move our business objects...
2
by: mia23 | last post by:
Hello, I am a java beginner and I need series help in solving this program; my assignment is due after 2 days and I can't understand this program . This is THE PROGRAM:  The ABC medical clinic...
5
by: PeaceLovinHippy | last post by:
Hello im new to java & im working on some mods for a game - below is a small part which im working on . however im getting errors due to something wrong in the code - can anyone please help me...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.