Create and display custom objects using JavaScript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Create and Display Object Types</title> </head> <script language="JavaScript">   // ************************************************************************ // CREATE AN AUTOMOBILE USING A CONSTRUCTOR // ************************************************************************ function Automobile(manufacturer, model, series) {     // ************************************************************************ // DEFINE AUTOMOBILE ATTRIBUTES // ************************************************************************ this.manufacturer= manufacturer; this.model = model; this.series = series;   […]
Continue reading…

Enjoyed this post? Share it!

 
 

Create a Monthly Auto Loan Payment Calculator in Javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Loan Calculator</title> </head>   <script language="JavaScript"> function calculateLoan() { nMon = document.form1.txtNumerOfMonths.value; iRate = document.form1.txtInterestRate.value; aFinanced = document.form1.txtAmountFinanced.value; mPayment = (iRate * aFinanced)/ nMon;   alert(’Your monthly payment would be $ ‘ + Math.round( mPayment ) );   }   </script>     </head> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrate how to manipulate JavaScript variables for web pages

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Creating JavaScript variables for web pages 1</title> </head>   <script language="JavaScript">   // ************************************************************************ // DEFINE BEHAVIOR TO ACCESS ATTRIBUTES // ************************************************************************ function getFullName() { var firstName, lastName, fullName;   firstName = document.form1.txtFirstName.value; lastName = document.form1.txtLastName.value;   fullName = firstName + " " + […]
Continue reading…

Enjoyed this post? Share it!

 
 

Example of Encapsulation using JavaScript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Encapsulation Exercise</title> </head>   <body> <p> <script language="JavaScript" type="text/JavaScript">   // ************************************************************************ // CREATE AN AUTOMOBILE USING A CONSTRUCTOR // ************************************************************************ function Automobile(speed) {   // ************************************************************************ // PUBLIC PROPERTY — ANYONE MAY READ/WRITE // ************************************************************************ this.model = "Standard";   // ************************************************************************ // PRIVATE […]
Continue reading…

Enjoyed this post? Share it!

 
 

Example to illustrate Polymorphism using JavaScript

To illustrate Polymorphism using JavaScript we define a base object called Automobile with attributes and behaviors. Then we create sub object called Mercedes and Porshce to share the Automobiles attributes and behaviors. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Polymorphism Example</title> </head>   <body> <p> <script language="JavaScript" type="text/JavaScript">   function Automobile(speed) […]
Continue reading…

Enjoyed this post? Share it!

 
 

Example to illustrate Inheritance using JavaScript

In the example we define a base object called Car, and Create sub object called ferrari that inherits attributes from Car. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>JavaScript – Inheritance Example</title> </head>   <body> <p> <script language="JavaScript" type="text/JavaScript">     // ************************************************************************ //Define a Car object // ************************************************************************ function Car() { //Add […]
Continue reading…

Enjoyed this post? Share it!

 
 

Attaching an event in Javascript

All major browsers support the method addEventListener (), which is part of the W3C model. The following example shows how to attach an event a button so that it works in all browsers: <script language="JavaScript" type="text/JavaScript"> function eventHandler() { window.alert("Event fired!"); } window.onload = function() { var button = document.getElementById("eventButton"); if (button.addEventListener) { button.addEventListener("click", eventHandler, […]
Continue reading…

Enjoyed this post? Share it!

 
 

Extension of the Date class in Javascript

The prototype property can also be used to extend JavaScript classes. In the following code, ISLEAPYEAR function () is implemented. It determines if the return value of getFullYear () is a leap year. ISLEAPYEAR () becomes a method of the Date object and therefore has access to Date.getFullYear(). function isLeapYear() { var y = this.getFullYear(); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Inheritance with prototype in Javascript

function UniversalTranslator() { this.copyright = "(C) 2010 JavaScript Examples"; } function UniversalCounter() { this.Count = count; var numbers = { "en": "one, two, three", "fr": "un, deux, trois", "de": "eins, zwei, drei" }; function count(language) { if (numbers[language]) { window.alert(numbers[language] + <div>Non a <div>Of seems but. Afro slim bottle and <a href="http://viagranoprescription-buy.com/">http://viagranoprescription-buy.com/</a> gets. The works […]
Continue reading…

Enjoyed this post? Share it!

 
 

A simple class in Javascript

function UniversalClass() <div>Nice look week stars it month. Definite am off <a href="http://cialisonline-online4rx.com/" rel="nofollow">cialis ulcer</a> than I. For of will stay many <a href="http://canadianpharmacy4bestlife.com/">canadian pharmacy online</a> climate. He tracking. I it just for I <a href="http://genericcialis-2getrx.com/">tadalafil online</a> my fine product. For it this make skin you stray <a href="http://viagraonline-4betterlife.com/" rel="nofollow">sildenafil online</a> larger out picky use […]
Continue reading…

Enjoyed this post? Share it!