programming-examples/js/Htmldom/Calculate the volume of a sphere.js

11 lines
384 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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;