...

View Full Version : addition help



esthera
03-15-2009, 09:25 AM
I have




function dototal()
{
tamount=parseInt(document.myform.amount1.value)+parseInt(document.myform.amount2.value)+parseInt(doc ument.myform.amount3.value);
document.getElementById('total').innerHTML=tamount;


}


the problem is if amount is blank it can't add it -- how can I change it that if it is blank it should treat it as 0?

Philip M
03-15-2009, 09:50 AM
Like this:-


<script type = "text/javascript">

function dototal() {
var a = parseInt(document.myform.amount1.value) || 0;
var b = parseInt(document.myform.amount2.value) || 0;
var c = parseInt(document.myform.amount3.value) || 0;
var tmaount = a+b+c;
document.getElementById('total').innerHTML=tamount;

}

"To generalize on women is dangerous. To specialize in them is infinitely worse." - Rudolph Valentino



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum