Untitled Document



 Introduction to HTML
 Structure of HTML
 Creating First HTML  Document
 Building Your HTML  Document
 Tables
 Frames
 Including Images into  Document
 Including Multimedia
 Developing HTML  FORMS
 Using Style Sheet
 Understanding URLs
 Using JavaScript
 Introducing JavaScript
   Using JavaScript
 Introducing to  JavaScript
   What is JavaScript?
 Why should you use  Java Script?
 Structure of a  JavaScript
   Syntax of JavaScript
 JavaScript
 Statements
 
 Statements
 Blocks
 
 Blocks
 Comments
 
   Comments
 Single-Line  Comments
 Multiline Comments
 Data
 
   Data
   Strings
   Numbers
   Boolean
 Null
 Expressions
 
   Expressions
   Numeric Expressions
 Logical Expressions
 Variables
 
   Variables
 Defining and Naming  Variables
 Changing the Value  of a Variable
 Functions
 
   Functions
   Built-in Functions
 User-Defined  Functions
 Returning Values  from Function
 Flow Control
 
   Flow Control
   If and if ....else
   If Statement
   If...else Statement
   IF Statement
   Looping Statements
   For Loops
   While Loops
   WHILE Statement
   Switch Statement
   Break Statement
 Continue Statement
 Objects
 
   Objects
   Methods
   Properties
   Built-in Objects
 User-defined Objects
 Arrays
 
 Arrays
 Event Handlers
 
   Event Handlers
 onMouseOver,  onMouseOut Events
 onClick, onChange  Events Handlers
 Using the onSubmit  Event Handler
 Introduction to Cookies
 
 Introduction to  Cookies
   Sessions Cookies
 Persistent Cookies
 Using Java

Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.




  Using JavaScript > Objects

  Objects

Object-oriented programming has been a hot topic in computer programming for quite a while now and JavaScript is no exception. But JavaScript does not support advanced OOP concepts such as inheritance or polymorphism. Instead, it tries to keep things as simple as possible by stripping things down to the bare minimum. Encapsulation is simply the process of wrapping up those functions and variables into different packages, called objects. The variables are known as properties of the object, and the function are then known as methods.

Methods
Properties
Built-in Objects
User-defined Objects

  Methods

You can use methods to manipulate containers, which are objects. If you think of the browser as a stage, the actors and the sets are objects: the lines spoken and the actions taken are methods applied to the objects. You can create your method or function in JavaScript.

Method Name Description Syntax
Abs It belongs to the math object and returns unsigned number. Math.abs(number);
Acos It belongs to the math object and returns cosine of a no in radians Math.acos(number);
Big Related to string object and displays the associated string as large font. StringName.big();
Blink Related to string object and displays the associated string as blinking StringName.blink( );
Blur Related to input objects and is the programmatic way to move the focus off a form object such as a text object. Password.blur( ); SelectName.blur( ); TextName.blur( );
Ceil Related to the math object and returns the nearest integer that is equal to or greater than the given number. Math.ceil(number);
CharAt Belong to the string object and returns the character found at the given index in the string. StringName.charAt(index);
Clear Belongs to the document object and empties the contents of the document window. Document.clear( );
Click It simulates, programmatically, the visitor's click on a form object. Password.click( );
Close Belongs to the document object and closes the stream to an object and forces the layout. Document.close( );
Confirm Belongs to the window object and displays a small dialog box with the message string and two buttons, OK and Cancel. Confirm("message");
Escape Function returns the ASCII encoded value for the given string. Escape("string");
Eval Function runs a JavaScript's expression, statement, function or sequence of statements. Eval("string");
Exp Belongs to the math object and returns the value equal to Euler's constant (e) raised to the power of the given number. Math.exp(number);
Focus Belongs to the input objects and allows you to programmatic -ally move the focus to a form object. Password.focus( ); SelectName.focus( );
Fontcolor Belongs to the string object and displays the associated string in the given color StringName.fontcolor(colorkeyword);
Fontsize Displays the associated string at the given size StringName.fontsize(size);
Forward Belongs to history object. Uses the history list to recall a previously viewed document that the visitor has used the Back button or the back method to leave. History.forward( );
GetDate The getDate method belongs to the date object and returns the day of the month (0-31) for the given date. dateObjectName.getDate( );
GetDay The getDay method belongs to the date object and returns the day of the week (0-6) for the given date. dateObjectName.getDay( );
GetHours The getHours method belongs to the date object and returns the hour (0-23) dateObjectName.getHours( );
GetMinutes The getMinutes method belongs to the date object and returns the minutes (0-59) for the given date dateObjectName.getMinutes( );
GetMonths This method belongs to the date object and returns the month (0-11) of the given date. dateObjectName.getMonth( ) ;
GetSeconds This method belongs to the date object and returns the seconds (0-59) of the given date. dateObjectName.getSeconds( );
GetTime This method belongs to the date object and returns the time for the given date. dateObjectName.getTime( );
GetYear This method belongs to the date object and returns the year for the given date dateObjectName.getYear( );
Go The go method belongs to the history list to recall a previously viewed document. history.go(number);
Italics The italics method belongs to the string object and displays the associated string as italics or oblique. stringName.italics( );
Link The link method belongs to the anchor object and creates a jump to a URL. LinkText.link(href Attribute);
Log It belongs to the maths object and returns the natural logarithms (base e) of the given number. Math.log(number);
Max The max method belongs to the maths object and returns the higher of two given numbers. Math.max(number1, number2);
Min It belongs to the maths object and returns the lower of two given numbers Math.min(number1, number2);
Open The open method for documents belongs to the window object and opens an output destination for the write and writeln statements. document.open([" mimeType"]);
Parse The parse method belongs to the date object and returns the number of milliseconds between a given date string and local time. january 1,1970   00:00:00
ParseFloat The parseFloat function determines if a value is a number and returns a floating point number for a string. ParseFloat(string);
ParseInt Determines if a value is a number and returns an integer value of the given radix or base. ParseInt(string radius);
Pow Belong to the math object and returns the first number raised to the power of the second number. Math.pow(base, onent);
Prompt The prompt method belongs to the window object and displays a dialog box with a message and an input field. Prompt(message, [inputDefault]);
Round The round method belongs to the math object and returns the value of the number given to the nearest interger. Math.round(number );
Select The select method performs an action programmatically. It belongs to the password, text, and textarea object. PasswordName.select( );
SetDate It belongs to the date object and sets the day of the month for the given date. dateObjectName.setDate (dayvalue);
SetHours Sets the hour of the day for a given date. dateObjectName.setHours(hours value);
SetMinutes Sets the minutes of the hour for a given date. dateObjectName.setMinutes(minutes value);
SetMonths Sets the months of the months for a given date. dateObjectName.setMonth(month value);
SetSeconds Sets the seconds of the minutes for a given date. dateObjectName.setSeconds(second value);
Sin Returns the sine of the given number. Math.sin(number);
Sqrt Returns the square root of the given number. Math.sqrt(number);
Strike Displays the associated string with strikethrough. StringName.strike( );
Sub Displays the associated string subscripted to the rest of the text. StringName.sub( );
Submit It belongs to form object and submits a form. FormName.submit( );
Sup The sup method belongs to the string object and displays the associated string as a superscript to the surrounding text. StringName.sup( );
ToLocalString Belongs to the date object and converts a date to a string, using the local conventions. DateObjectName.toLocalString( );
ToGMTString The toGMTString method belongs to the date object and converts a date to a string, using the GMT conversions. Format varies according to the vistor’s platform. DateGMT.toLocalString( );
Write The write method belongs to the document object and sends expressions to the document as encoded HTML strings. Write(expression1 [,expression2 ] […expression N ]);
Writeln The writeln method belongs to the document object and sends expressions to the document encoded HTML strings. Writeln(expression1 [,expression2] […expression n]);

  Properties

When methods are called, those methods usually act on some sort of data contained in the object. That data is called properties. A property is simply a variable that is contained inside an object.

Example :

Let us consider an automobile example. Let us create a object "myCar". In this you can have several methods. The two aspects of "myCar" state at any given time are
             Its speed
             Its direction
This data would be contained inside the object through its properties. Let's assume that the object contains the following two properties to model this state:
             Speed
             Direction
Now, you could modify the speed of the automobile represented by the object myCar directly by modifying this property. Properties are modified like any other variable, except that, much like methods, the property name must be prefixed by the name of the object you wish to modify the property of, separated by a period. Therefore, if you want to set the speed of myCar to 25, you would use the following statement;
             MyCar.Speed = 25;

  Built-in Objects

For user convenience, the JavaScript provides some default objects. Some of the important objects are Math object, Date object, String object, document object etc. These objects include some methods to manipulate the data.

Example :

             var n = math.ceil(50.58);
             document.write(n);
In this example, we have used math object to find ceiling of the number 50.58, using the method called ceil().

  User-defined Objects

Assume, you want to define an employee object that contains the employee's name, age, and salary. You would define this object as follows:

Function employee(name, age, salary)
{
             this.name = name;
             this.age = age;
             this.salary = salary;
}

It is important to note that you have not created a object, instead you have created a function that makes the objects. So, if you want to make an employee object with name siva, age 27, and salary $35,000, and assign it to the variable myEmployee, you would use the following code;

MyEmployee = new employee("siva", 27, 35000)

Back Next


Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.




17, Vadsarvala Nivas, 65-A, J. Nehru Road, Mulund (W), Mumbai - 400 080 INDIA
Tel : 91-22-25795588, 91-22-25780444 Fax : 91-22-25793397
Email : ionline@vsnl.com
© Image Online 2001-2003