Hello,
I’m new here and I hope I’m in the correct category…
First, sorry for my bad english, I’m from switzerland.
I need help with JavaScript. I have copied this calculator but I can’t change it.
[code=html]<script language =”JavaScript”>
<!–
function calculate_finance() {
amount = document.getElementById(‘calc_amount’).value.replace(‘,’,’.’);
amount = amount.replace(/[^0-9.]/g, ”);
if (amount <= 99.99) {var period = 30; var interest = 2.4; var deviation_percent = 2.4; }
else if (amount >= 100.00 && amount <= 999.99) {var period = 60; var interest = 2.8; var deviation_percent = 2.8; }
else if (amount >= 1000.00 && amount <= 3000.00) {var period = 90; var interest = 3.4; var deviation_percent = 3.4; }
compound = parseInt(document.getElementById(‘calc_compounding’).value);
if (compound > 100) compound = 100;
else if ((compound < 0) || (isNaN(compound))) compound = 0;
document.getElementById(‘calc_compounding’).value = compound;
var profit = this_profit = direct = this_direct = first_profit = last_profit = total_profit = deviation = 0;
for (i=0; i < period; i++) {
profit = Math.round((amount*1 + this_profit*1) * interest)/100;
direct = Math.round(profit*(1-compound*0.01)*100)/100;
if (first_profit == 0) first_profit = profit;
last_profit = profit;
profit -= direct;
this_profit += profit*1;
this_direct += direct*1;
}
total_profit = Math.round((this_profit*1 + this_direct*1)*10)/10;
total_profit = isNaN(total_profit)?0:total_profit;
daily_profit = Math.round(total_profit*10/period)/10;
total_return = Math.round(total_profit*10+amount*10)/10;
if (total_return < 1000) {
total_return = Math.round(total_profit*10+amount*10)/10;
deviation = Math.round(total_return*deviation_percent*0.5*10/100)/10;
}
else {
total_return = Math.round(total_profit*1+amount*1);
deviation = Math.round(total_return*deviation_percent*0.5/100);
}
deviation = deviation<0.1?0.1:deviation;
roi_min = Math.round((total_return-deviation)*1000/amount)/10;
roi_max = Math.round((total_return+deviation)*1000/amount)/10;
roi = isNaN(roi_max)?0:roi_min+’ <small>%</small> – ‘+roi_max;
document.getElementById(‘calc_total_return’).innerHTML = ‘<b>’+total_return+'</b> $’;
document.getElementById(‘calc_roi’).innerHTML = ‘<b>’+roi+'</b> %’;
document.getElementById(‘calc_period’).innerHTML = ‘<b>’+period+'</b> ‘+ (period<100?’business ‘:’b/’) + ‘days’;
//document.getElementById(‘calc_end_date’).innerHTML = ‘<b>’+end_date+'</b>’;
document.getElementById(‘calc_amount’).value = amount;
if (deviation>0) document.getElementById(‘calc_deviation’).innerHTML = ‘±<b>’+deviation+'</b> $’;
else document.getElementById(‘calc_deviation’).innerHTML = ”;
}
function save_calc_data() {
amount = document.getElementById(‘calc_amount’).value.replace(‘,’,’.’);
amount = amount.replace(/[^0-9.]/g, ”);
if (amount < 5) {
amount = 5;
document.getElementById(‘calc_amount’).value = amount;
}
document.cookie=”calc_amount=”+amount+”; path=/; expires=Mon, 01-Jan-2018 00:00:00 GMT”;
document.cookie=”calc_compounding=”+document.getElementById(‘calc_compounding’).value +”; path=/; expires=Mon, 01-Jan-2018 00:00:00 GMT”;
calculate_finance();
}
–>
</script>
<div id=”bottom-container-3″ class=”container-col-33″>
<div class=”padding-10″>
<img class=”left ml-10″ src=”/img/bottom-container-calculator.png” height=”38″ width=”42″ alt=”Financial calculator”>
<h3>Financial Calculator</h3>
<div class=”h-20″></div>
<div class=”financial-calc”>
<table>
<tr>
<td width=82><label>Investment<br >amount</label></td>
<td width=55><input type=”text” id=”calc_amount” onblur=”calculate_finance();” onkeyup=”javascript:this.value=this.value.replace(/[^0-9.,]/g, ”); calculate_finance();” onchange=”save_calc_data();” value=”100″></td>
<td width=10> </td>
<td width=70><label>Total<br />return</label></td>
<td class=”data”><span id=”calc_total_return”><b>118</b> $</span> <span id=”calc_deviation”>±<b>2.4</b> $</span></td>
</tr>
<tr>
<td><label>Compounding</label></td><td><input type=”text” id=”calc_compounding” onblur=”calculate_finance();” onkeyup=”javascript:this.value=this.value.replace(/[^0-9.,]/g, ”); calculate_finance();” onchange=”save_calc_data();” value=””></td>
<td> </td>
<td><label>Period</label></td><td class=”data”><span id=”calc_period”><b>10</b> calendar days</span></td>
</tr>
<tr>
<td colspan=2> <!–<label>End date</label></td><td class=”data”><span id=”calc_end_date”><b></b></span>–></td>
<td> </td>
<td><label>ROI</label></td><td class=”data”><span id=”calc_roi”><b>160</b> %</span></td>
</tr>
</table>
<script language =”JavaScript”>calculate_finance();</script>
</div>
</div>
</div></div>
I want to add this (red text) but when I add:
[CODE]document.getElementById(‘daily_profit’).innerHTML = ‘<b>’+daily_profit+'</b> $’;
and this in the table:
[code=html]<tr>
<td colspan=2> <!–<label>End date</label></td><td class=”data”><span id=”calc_end_date”><b></b></span>–></td>
<td> </td>
<td><label>ROI</label></td><td class=”data”><span id=”daily_profit”><b>160</b> %</span></td>
</tr>
it will change the period to 10 days… I can’t fix that. Any ideas?