Get Square root Using javaScript

Chikul
Posted by Chikul under JavaScript category on | Views : 6209
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Get Square root Using javaScript</title>
<script language="javascript" type="text/javascript">
function fnGetSqrt()
{
var vNum=document.getElementById("txtNum").value;
var validate = /^[0-9.]+$/;
var validate = validate.test(vNum);
if (validate)
{
var vResult=Math.sqrt(vNum);
document.getElementById("sqrtRoot").value=vResult;
return false;
}
else
{
window.alert("Please enter a positive number to get a square root.");
return false;
}
}

</script>

</head>
<body>
<form id="form1" runat="server" onsubmit="return fnGetSqrt()" >
<div>
Enter Number : <input type="text" id="txtNum" name="txtNum" size="5" /><br />
Square Root : <input type="text" id="sqrtRoot" name="sqrtRoot" size="20" /><br />
<input type="submit" value="Get Square Root!" />
</div>
</form>
</body>
</html>

Comments or Responses

Login to post response