The external javascript as well, sorry I couldn't send a link to the files themselves,I'm not really sure how to do that.
function calculate(){
'use strict';
var volume;
var radius = document.getElementById('radius').value;
radius = Math.abs(radius);
volume = (4/3) * Math.PI * Math.pow(radius, 3);
volume = volume.toFixed(4);
document.getElementById('volume').value = volume;
return false;
}
function init (){
'use strict'
document.getElementById('theform').onsubmit = calculate;
}
window.onload = init;
Try
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Volume of a Sphere</title>
<style>
body {
padding-top: 30px;
}
label,
input {
display: block;
}
</style>
</head>
<body>
<p>Input radius value and get the volume of a sphere.</p>
<form action="" method="post" id="MyForm">
<label for="radius">Radius</label><input type="text" name="radius" id="radius" required>
<input type="submit" value="Calculate" id="submit">
<label for="volume">Volume</label><input type="text" readonly name="volume" id="volume">
</form>
<script>
function volume_sphere() {
var volume;
var radius = document.getElementById('radius').value;
radius = Math.abs(radius);
volume = (4/3) * Math.PI * Math.pow(radius, 3);
volume = volume.toFixed(4);
document.getElementById('volume').value = volume;
return false;
}
window.onload = document.getElementById('MyForm').onsubmit = volume_sphere;
</script>
</body>
</html>