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 > Functions

  Functions

A function is a block of code with a defined name that might or might not take one or more arguments. Functions are called by name, which takes the following form: foo(bar); The parentheses encloses any arguments that the function might take. In this instance the function named foo takes one argument named bar. Function can also return values, although they do not necessarily have to. You don't necessarily have to do anything with these return values, but they usually return a value for a good reason, so it's best not to ignore them.

  Built-in Functions

Some of the important built-in function used in JavaScript are given below:

Functions Description
Escape(charstring) Returns the conversion of charstring into a form that displays in the browser without HTML markup.
Eval(codestring) Evaluates codestring as JavaScript code, returning anthing that Javascript returns.
IsName(numvalue) Returns true if numvalue is not a number, otherwise returns false--- used wit parseFloat and parselint.
ParFloat(numstring) Return numstring converted to an float, if it cannot be converted, returns the reserved value NaN.
Parsient(numstring) Return numstring converted to an Integer, if it cannot be converted, returns the reserved value NaN.
Unescape(charstring) Returns the conversion of charstring back into a form that displays in the browser with HTML markup (the oppositer or escape).

Example :

<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT language = "JavaScript">
              var addmeval = "2+2";
              addmeval = evalu(addmeval);
              document.write(addmeval);
</SCRIPT>
</BODY>
</HTML>

  User-Defined Functions

You can create your own function in JavaScript. A function is defined by combining a function statement and a block of code to associate with that function. The function statement consists of the word function, followed by parentheses containing the name of the function.

Syntax :

function functionname(argument) {
           Block statement…….
}

Example :

function output(theText)
{
   theText = eval(theText);
   document.write(theText);
}

  Returning Values from Function

Data can be returned from a function by using the keyword return, followed by the data to be returned.

Example :

The following simple function takes a number and returns the square of that number to the calling expression:

function square(inNum)
{
return(inNum * inNum);
}

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