Javascript tends to make concatenation rather than additions. Then it's always careful to begin with the multiplications to force Number conversions...
Code:
function calculateText(){
var op1=parseFloat(document.getElementById('height'));
0var op2=parseFloat(document.getElementById('width'));
var op3=parseFloat(document.getElementById('length'));
var result=op1*op2*op3/166;
if (!result || isNaN(result)) {alert("The values seems erroneous...");return}
result=result.toFixed(2);
document.getElementById('resultSpan').innerHTML=result;
}
<script>
function calculateText(){
var op1=parseFloat(document.getElementById('height'));
var op2=parseFloat(document.getElementById('width'));
var op3=parseFloat(document.getElementById('length'));
var result=op1*op2*op3/166(document.getElementById('total'));
if (!result || isNaN(result)) {alert("The values seems erroneous...");return}
result=result.toFixed(2);
document.getElementById('resultSpan').innerHTML=result;
}
</script>
Doesn't seem to work. I'm using this in conjunction with a form component "RSFORM!PRO" for my website. I used the example here, but all it does is add.
Bookmarks