function calculation() { var d = document; var pwr_sel = d.getElementById('power_rating_2'); var pwr = pwr_sel[pwr_sel.selectedIndex].value d.getElementById('power_rating_1').innerHTML = pwr/5; var kvt = d.getElementById('kvt').value; var cost_1 = pointify(d.getElementById('cost_1').value); //if (cost_1==0) return; var cost_2 = pointify(d.getElementById('cost_2').value); //if (cost_2==0) return; if (cost_1==0) cost_1 = 130; if (cost_2==0) cost_2 = 7; d.getElementById('cost_1').value = cost_1; d.getElementById('cost_2').value = cost_2; var life_time_1 = d.getElementById('life_time_1').value; var life_time_2 = 1000; if (life_time_1==0) life_time_1 = 8000; d.getElementById('life_time_1').value = life_time_1; d.getElementById('life_time_2').innerHTML = life_time_2; var eko_1 = -cost_1+(cost_2*(life_time_1/life_time_2)) d.getElementById('eko_1').innerHTML = trimTo2(eko_1); var eko_2 = (4*pwr/5)*kvt; d.getElementById('eko_2').innerHTML = trimTo2(eko_2); var eko_3 = eko_2*(life_time_1/life_time_2); d.getElementById('eko_3').innerHTML = trimTo2(eko_3); var itogo = eko_1+eko_3; d.getElementById('itogo').innerHTML = trimTo2(itogo); } function pointify(val) { val = val.replace(/,/,'.') if (/\.$/.test(val)) { val += '0' } return val } function trimTo2(val) { var v = new Array(); v = val.toString().split('.'); if (v.length>1) { v[1] = v[1].substr(0,2) val = v.join('.') } return val } calculation();