Using Functions in JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>use of functions</title>
<script>
var arr=[10,20,30];
function displayValue(curObj)
{
// alert(value);
curObj.value="new Text";
ans=sum(10,20);
alert("The value of ans is " + ans);
addValues(arr);
}
function sum(n1,n2)
{
res=n1+n2;
return res;
}
function addValues(myarr)
{
//alert(myarr.length);
var sum1=0;
for(i=0;i<myarr.length;i++)
{
sum1=sum1+myarr[i];
}
alert(sum1);
}//end of function
</script>
</head>
<body>
<h1>use of functions</h1>
<form>
<input type="text1" id="text1" id="text1">
<input type="button" value="simple function" onclick="displayValue(this)">
<input type="button" value="Second Button" onclick="displayValue(this)">
</form>
</body>
</html>
Comments
Post a Comment