Breaking News
yeni film izle hd film seyret film izle

Parameterized functions IN Java Script

Function is a set of statements recognized by a name and can be used as and when required (it is reusable).

A function can accept parameters and can used those accepted values for his purpose. A function can accept many parameters to which we can manage or use as per requirement in the code of that function.

 
Syntax:
 
function functionname(var1, var2,..)

{

lines to be kept under this name

}

 
Example:
 
<html>

<head>

</head>

<body>

<script type=”text/javascript”>

function ff(f1)

{

var a,b,c

a=parseInt(f1.t1.value)

b=parseInt(f1.t2.value)

c=parseInt(f1.t3.value)

if (a>b && a>c)

{

f1.t4.value=”First Value is greatest”

}

if (b>a && b>c)

{

f1.t4.value=”Second Value is greatest”

} if(c>a && c>b)

{

f1.t4.value=”Third Value is greatest”

}

}

</script >

<form name = “f1”>

Enter first Value<input type=”text” name=”t1″><br>

Enter Second Value<input type=”text” name=”t2″> <br>

Enter Third Value<input type=”text” name=”t3″> <br>

<input type=”Button” value=” Hit me” name=”b1″ onClick=”ff(f1)”><br>

Result<input type=”text” name=”t4″> <br>

<input type=”reset”>

</form>

</body>

</html>

 
Understanding program:
In the above program we type numeric values in top three textboxes and on clicking on hit me button we get result in fourth textbox which one value is greater.
Click here to view result of this program on browser
 
Example:
 
<html>

<head>

</head>

<body>

<script type=”text/javascript”>

function ff(f1)

{

document.bgColor=f1.t1.value;

}

</script >

<form name = “f1”>

Enter the Background Color you want<input type=”text” name=”t1″> <br>

<input type=”Button” value=” Hit me” name=”b1″ onClick=”ff(f1)”>

</form>

</body>

</html>

 
 
Understanding program:
we created a button and onclick event of that button we called the function ff() , to which we passed the function name (f1), this f1 (form) contains a textbox named t1, the value of t1 on form f1 can be accessed by f1.t1.value to which we are assigning to the background color of document so whatever color you will type in the text box will appear on the background.

Check Also

Recursive Functions In Java Script

A function which calls itself, is called a recursive function. When A function calls itself …