This is a simple dropdown with values. I'm trying to pull the values as currency then add.
The values aren't being added (1+1=2 or 1+2=3) but instead are concatenating (1+1=11 or 1+2=12). Where am I going wrong here?:
<script>
function displayResult()
{
var strm=document.getElementById("matt").options[document.getElementById("matt").selectedIndex];
var t=strm.text.search("\\\$");
var strb=document.getElementById("box").options[document.getElementById("box").selectedIndex];
var b=strb.text.search("\\\$");
var x=strm.text.substr(t+1);
var y=strb.text.substr(b+1);
var math= x + y;
alert(strm.text.substr(t+1));
alert(strb.text.substr(b+1));
alert(math);
}
</script>
<form>
Select #1:
<select id="matt">
<option>$1.00</option>
<option>$2.00</option>
</select>
<br />
Select #2:
<select id="box">
<option>$3.00</option>
<option>$4.00</option>
</select>
</form>
<button type="button" onclick="displayResult()">Display index</button>
mathis probably not a good variable name. but then again, neither arestrm,t,strb,b,x, ory... are you a minifier?