Pat,
eval() :icon_eek:
It's part of javascript but seldom needs to be used; arguably never.
Number() returns a floating point conversion of its argument.
function doMath() {
var one = Number(document.theForm.elements[0].value);
var two = Number(document.theForm.elements[1].value);
ans = one * two;
outp = " " + "$" + ans.toFixed(2) + "/Month";
document.getElementById('outtab').innerHTML = outp;
}
Remember to terminate each statement with a ; . Javascript does its best but may one day do something unexpected with unterminated statements. Proper termination also aids readability of the code.Airshow
Airshow
WiFi Lounge Lizard
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Pat,
Your code will simplify considerably by using the option values to store the unit prices.
function switchme(sel) {
var value = sel[sel.selectedIndex].value;
document.getElementById("price").innerHTML = value.toFixed(2);
}
<select id="selection" name="one" onchange="switchme(this)">
<option value="Choose">Please Choose</option>
<option value="2">5</option>
<option value="1">10</option>
<option value="0.75">15</option>
<option value="0.5">20</option>
<option value="0.45">30</option>
<option value="0.4">50</option>
<option value="0.34">100</option>
</select>
Airshow
Airshow
WiFi Lounge Lizard
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372