Object-Oriented Planetary Data Presentation : Objects Object Oriented « Language Basics « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » Language Basics » Objects Object Oriented 
Object-Oriented Planetary Data Presentation
 
/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

John Wiley & Sons CopyRight 2001
*/


<HTML>
<HEAD>
<TITLE>Our Solar System</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- start script
// method definition
function showPlanet() {
    var result = "<HTML><BODY><CENTER><TABLE BORDER=2>"
    result += "<CAPTION ALIGN=TOP>Planetary data for: <B>" this.name + "</B></CAPTION>"
    result += "<TR><TD ALIGN=RIGHT>Diameter:</TD><TD>" this.diameter + "</TD></TR>"
    result += "<TR><TD ALIGN=RIGHT>Distance from Sun:</TD><TD>" this.distance + "</TD></TR>"
    result += "<TR><TD ALIGN=RIGHT>One Orbit Around Sun:</TD><TD>" this.year + "</TD></TR>"
    result += "<TR><TD ALIGN=RIGHT>One Revolution (Earth Time):</TD><TD>" this.day + "</TD></TR>"
    result += "</TABLE></CENTER></BODY></HTML>"
    // display results in a second frame of the window
    document.write(result)
    document.close()
}
// definition of planet object type;
// 'new' will create a new instance and stuff parameter data into object
function planet(name, diameter, distance, year, day) {
    this.name = name
    this.diameter = diameter
    this.distance = distance
    this.year = year
    this.day = day
    this.showPlanet = showPlanet  // make showPlanet() function a planet method
}
// create new planet objects, and store in a series of variables
var Mercury = new planet("Mercury","3100 miles""36 million miles""88 days",
 "59 days")
var Venus = new planet("Venus""7700 miles""67 million miles""225 days""244 days")
var Earth = new planet("Earth""7920 miles""93 million miles""365.25 days","24 hours")
var Mars = new planet("Mars""4200 miles""141 million miles""687 days",
 "24 hours, 24 minutes")
var Jupiter = new planet("Jupiter","88,640 miles","483 million miles",
 "11.9 years""9 hours, 50 minutes")
var Saturn = new planet("Saturn""74,500 miles","886 million miles",
 "29.5 years""10 hours, 39 minutes")
var Uranus = new planet("Uranus""32,000 miles","1.782 billion miles",
"84 years""23 hours")
var Neptune = new planet("Neptune","31,000 miles","2.793 billion miles",
"165 years""15 hours, 48 minutes")
var Pluto = new planet("Pluto""1500 miles""3.67 billion miles""248 years""6 days, 7 hours")
// called from push button to invoke planet object method
function doDisplay(popup) {
    i = popup.selectedIndex
    eval(popup.options[i].text + ".showPlanet()")
}
// end script -->
</SCRIPT>
<BODY>
<H1>The Daily Planet</H1>
<HR>
<FORM>
<P>Select a planet to view its planetary data: 

<SELECT NAME='planetsList' onChange='doDisplay(this)'>
    <OPTION>Mercury
    <OPTION>Venus
    <OPTION SELECTED>Earth
    <OPTION>Mars
    <OPTION>Jupiter
    <OPTION>Saturn
    <OPTION>Uranus
    <OPTION>Neptune
    <OPTION>Pluto
</SELECT></P>
</FORM>
</BODY>
</HTML>

           
         
  
Related examples in the same category
1. Object utility: create, parse and profile
2. Define Object, use its instance
3. Define and use object
4.  Creating an Object and Using Object Instance Properties and Methods
5. The Book Object Definition
6. Complete Example of Using the employee, client, and project Objects
7. Source Code for the showBook() Example
8. Using the Book Object Constructor
9. Creating Objects Dynamically
10. Object to array
11. Utility class for JavaScript class definition
12. Create an object and add attributes
13. Use for in loop to display all attributes from an object
14. Display the properties from an object one by one
15. An object and its constructor
16. Use function as the object constructor
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.