I have cobbled together a script that takes a variable, does two separate math computations to it, and displays both answers on the screen.
I need for the script to place commas into both "generated" answers when the results exceed 1,000. (Notice, default values appearing in the HTML already have commas in place.)
However, I do not need for the results to show any trailing decimal points.
Here's my JavaScript and some accompanying HTML...
function return_selected(currentID) {
var savings = document.getElementById(currentID);
var valueCalc = savings.options[savings.selectedIndex].value;
return valueCalc;
}
// computing potential at 3%
function firstCalc() {
var calcPrice1 = return_selected('soldfor') * .03 - 595;
document.getElementById('savings3').innerHTML = "$" + calcPrice1;
return calcPrice1;
}
// computing potential at 6%
function secondCalc() {
var calcPrice2 = return_selected('soldfor') * .06 - 595;
document.getElementById('savings6').innerHTML = "$" + calcPrice2;
return calcPrice2;
}
document.addEventListener("DOMContentLoaded", firstCalc);
document.addEventListener("DOMContentLoaded", secondCalc);
// should listen for all select option
document.addEventListener("change", firstCalc);
document.addEventListener("change", secondCalc);
<!--HTML Routine to DISPLAY COMPUTATIONS -->**
<div class="box">
<div class="content">
<p>Start with this number
<select name="" id="soldfor">
<option value="100000">$100,000</option>
<option value="200000">$200,000</option>
<option value="300000">$300,000</option>
<option value="400000" selected>$400,000</option>
<option value="450000">$450,000</option>
</select>
</p>Compute a new number <span id="savings3">$11,405</span>
<p>
<p>and compute another number
<span id="savings6">$23,405</span>
</div>
</div>