Thursday, April 14, 2011

How to make a funtion in Java Script:



<html>
<head>
<script language="javascript">
//funtion with to paramenters
function power(x,y) //return the x to the power y
{
pow=1;
for(i=1;i<=y;i++)
pow=pow*x;
return pow; //how to return values
}
//function without paramenters
function display() /*use for getting the values from the form inputs and setting the power to the third text box */
{
var a=document.getElementById('f').value;
var b=document.getElementById('s').value;
var res=power(a,b);
document.getElementById('res').value=power(a,b);
}

</script>
</head>
<body>
<form >
<input type="text" id="f"/>
<input type="text"  id="s"/>
<input type="button" onclick="display()" value="Power" />
<input type="text" id="res" />
</form>

</body>
</html>

1 comment: