function DoCalc()//----------------------------------------------------------- { //document.write ("some kind of message") //this line causes problems ...? //Set initial value EstCGPerc = 0.1 //Could as well be zero for (iter=1; iter<8; ++iter) { var Cost = new Array(NoRows) var Contri = new Array(NoRows) var Withdrl = new Array(NoRows) //var Growth=0; //var AmntInvstd=0; EstCGPercPeriod = (EstCGPerc / NoRows) + 1 Growth = MyForm.ClVal.value - MyForm.OpVal.value; //alert(Growth) AmntInvstd = MyForm.OpVal.value; for (var x=1; x<=NoRows; ++x) { Cost[x] = MyForm.elements['oCost' +x].value; Contri[x] = MyForm.elements['oContri' +x].value; Withdrl[x] = MyForm.elements['oWithdrl'+x].value; Growth = Growth - - Cost[x] - Contri[x] - - Withdrl[x]; //alert(Growth) //AmntInvstd = EstCGPercPeriod *(AmntInvstd - - Contri[x-1] - Withdrl[x-1]); AmntInvstd = AmntInvstd - Cost[x] AmntInvstd = AmntInvstd * EstCGPercPeriod AmntInvstd = AmntInvstd - - Contri[x] - Withdrl[x] //alert(AmntInvstd) } if (AmntInvstd/MyForm.ClVal.value >0.9999 && AmntInvstd/MyForm.ClVal.value < 1.0001) break RecdCGPerc = MyForm.ClVal.value / AmntInvstd * (EstCGPerc - - 1) //alert("Try ..." + RecdCGPerc) EstCGPerc = RecdCGPerc - 1 //alert(AmntInvstd) } //End of iter loop AmntInvstd = Math.round(AmntInvstd) //MyForm.CalcdClVal.value = AmntInvstd ACalcdClVal.innerText=AmntInvstd MyForm.Growth.value = Growth; MyForm.CGPerc.value = EstCGPerc * 100 MyForm.CGPerc.value = Math.round(MyForm.CGPerc.value * 10)/10; //To round to 1 digit after point MyForm.CostPerc.value = MyForm.QGPerc.value - MyForm.CGPerc.value; MyForm.CostPerc.value = Math.round(MyForm.CostPerc.value * 10)/10 //To round to 1 digit Base = Growth / MyForm.CGPerc.value *100 MyForm.CostAmnt.value = parseInt(Base * (MyForm.QGPerc.value - MyForm.CGPerc.value)/ 100); }