A function declared in the javascript code on the page, can be called at other points with this syntax:
Code:
functionName ([parameters]);
that is, writing the name of the function, opening and closing parentheses at the end of it. If it is required to pass parameters, these should be inserted between the parentheses, separated by a comma if more than one:
Code:
functionName (param1, param2, ..., paramN);
For example, if we want the function test () is executed when the page html, insert the reference to same within the tag <body>, more specifically under the control onLoad event:
HTML Code:
<html>
<head>
<title> </ title>
<script language="JavaScript" type="text/javascript">
<! -
function test ()
{
// Block of statements
}
//-->
</ Script> </ head>
If we want to perform the function by pressing a button, we can use the onClick event:
HTML Code:
<html>
<head>
<title> </ title>
<script language="JavaScript" type="text/javascript">
<! -
function test () {
/ / Block of statements
}
//-->
</ Script>
</ Head>
<body>
<input type="submit" value="Run">
</ Body>
</ Html>
Bookmarks