JavaScript Parameters


Parameters of JavaScript Function

We can pass a parameter in a function, in the sense we give the value or variable name so that the function can be executed based on these parameters. At the moment we pass some parameters into the function, these parameters are separated by a comma, either at the time of declaration or at the time of the call.

See the example below: we will create a JavaScript program that displays a dialog box:


<HTML>
<HEAD>
<script Language="JavaScript">
<! -
View1 function () {
         alert ('Text 1');
}
Show2 function () {
         alert ('Text 2');
}
//-->
</ SCRIPT>
</ HEAD>
<BODY>
<A HREF="javascript:;" onClick="Show1();"> Text1 </ A>
<A HREF="javascript:;" onClick="Show2();"> Text2 </ A>
</ BODY>
</ HTML>

Or the two following ways will give the same results:
<HTML>
<HEAD>
<script Language="JavaScript">
<! -
function Show(text) {
alert (text);
}
//-->
</ SCRIPT>
</ HEAD>
<BODY>
<A HREF="javascript:;" onClick="Show ('Text1');"> Text1 </ A>
<A HREF="javascript:;" onClick="Show ('Text2');"> Text2 </ A>
</ BODY>
</ HTML>

The end result of both programs is the same, but the second program is more flexible because we only have one function that can display any text.

0 comments:

Post a Comment