Calculate the square root of a number in JavaScript

Description

The following code shows how to calculate the square root of a number.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--  w ww  . j  a va2  s . c o m-->
function doMath(){
var inputNum1=document.form1.input1.value;
var result = Math.sqrt(inputNum1);
document.form1.answer.value = result;
}
</script>
</head>
<body>
<form name=form1>
Enter Number:
<input type="text" name="input1" size=10>
<input type="button" value="Calculate" onClick='doMath()'>
<br>
The square root is:
<input type="text" name="answer" size=20>
</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Calculate the square root of a number in JavaScript
Home »
  Javascript Tutorial »
    Development »
      Math
Javascript Tutorial Math
Calculate an exponent power in JavaScript
Calculate the absolute value of num in Java...
Calculate the arccosine of a number in Java...
Calculate the arctangent of the quotient of...
Calculate the cosine of a number in JavaScr...
Calculate the natural logarithm (base E) of...
Calculate the sine of a number in JavaScrip...
Calculate the square root of a number in Ja...
Calculates and returns the arcsine of a num...
Calculates the arctangent of a number in Ja...
Calculates the tangent of a number in JavaS...
Check if input value is a number from form ...
Convert Fahrenheit to Celsius back and fort...
Find out the max value in an array in JavaS...
Find out the min value in an array in JavaS...
Find out the value of PI in JavaScript
Find out the value of base 10 logarithm of ...
Find out the value of base 2 logarithm of e...
Find out the value of e, the base of the na...
Find out the value of natural logarithm of ...
Find out the value of natural logarithm of ...
Find out the value of square root of 2 in J...
Generate a random integer between 2 and 10 ...
Generate random URL in JavaScript
Get a random number between 1 and 10 in Jav...
Get a random number between values 0 and 1 ...
Get the max value in a list of parameter in...
Get the min value in a list of parameter in...
Math.round a random number in JavaScript
Round numbers down to the nearest integer v...
Round numbers up to the nearest integer val...
Round the number with Math.round() in JavaS...
Round to get the largest integer number equ...
Round to get the smallest integer greater t...
Select a random item from an array in JavaS...
Use Math.PI to do calculation in JavaScript
Use Recursive function to calculate Fibs in...