adding numbers extracted from strings javascript
<p>I am new to javascript and am trying to create a simple price calculator in javascript for my website (cupcake shop website). first, i have the user choose from a list of flavor choices and post that to a textarea, when the user selects vegan flavors, i would add $3.50 to the end when posting to the textarea, and when the user selects non vegan, the price is $2.75. everything posted to the textarea are strings. so for the calculator, I extract the last 5 characters (which is the price) and add them up to get a subtotal. I used a loop to go thru the list in the textarea to extract the numbers one by one and add them up, however, the calculation came out wrong. Can anyone tell me what is wrong with it???</p>

<pre><code>function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function addOption_list(selectbox){
var flavors = new Array("blueberry vegan","butterscotch","cappuccino vegan","carrot     
cake","carrot vegan","chocolate walnut vegan",
"chocolate peanut butter vegan","green tea &amp; chocolate","keylime","lavender     
vegan","lemon","lemon cream vegan","mandarin orange",
"mint chocolate","mocha","peanut butter &amp; double chocolate","raspberry swirl","red   
velvet","sesame","sesame oreo",
"strawberry","strawberry 2 vegan","tangerine","thia tea","triple   
chocolate","vanilla","very berry","vietnamese coffee","yuzu");
for (var i=0; i &lt; flavors.length;++i){

addOption(document.drop_list.flavors_list, flavors[i], flavors[i]);
}
}

var $ = function (id){
return document.getElementById(id);
}

var cart = [];
var update_cart = function(){
if(cart.length == 0){
    $("flavor_name").value = "";
} else{
    var list = "";
    for(var i in cart){ 
        list += (parseInt(i) +1) + ". " + cart[i] + /*":  $3.50" + */ "\n"; 
    }
    $("flavor_name").value = list;


    var sum = 0;
    for(var i = 0; i &lt; cart.length; i++){
        var price = parseFloat(list.substring(list.length - 5));
        sum += parseFloat( price.toFixed(2) );
    }

    $("subtotal").value = sum;
    var tax = parseFloat(($("subtotal").value * .08875).toFixed(2));
    $("sales_tax").value = tax;

    var total = parseFloat(price + tax).toFixed(2);
    $("total").value = total;

    }
}




var selectDropdown = function(){
    var dropdownValue=document.getElementById("flavors_list").value;
   // alert("You selected : " + dropdownValue);


if(dropdownValue == "blueberry vegan" || dropdownValue == "cappuccino vegan" ||   
       dropdownValue == "carrot vegan" || dropdownValue == "carrot vegan" ||
   dropdownValue == "chocolate walnut vegan" || dropdownValue == "chocolate peanut   
       butter vegan" || dropdownValue == "lavender vegan" || dropdownValue == "lemon   
       cream vegan" || dropdownValue == "strawberry 2 vegan"){
    alert("Adding " + dropdownValue + " to cart.");
    cart[cart.length] = dropdownValue + ":  $3.25";
    update_cart();
} else{
    alert("Adding " + dropdownValue + " to cart.");
    cart[cart.length] = dropdownValue + ":  $2.75";
    update_cart();
} 
}
</code></pre>

<p>HTML:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Home-Little Sweetie Cupcakes&lt;/title&gt;
&lt;link href="little_sweetie_styles.css" rel="stylesheet" type="text/css" /&gt;
&lt;link rel="Shortcut Icon" href="favicon.ico" /&gt;
&lt;script type="text/javascript" src="invoice.js"&gt;&lt;/script&gt;


&lt;/head&gt;

&lt;body onLoad="addOption_list()";&gt;
&lt;div class="cart_content"&gt;

    &lt;span class="content_title"&gt;
        Price Calculator
    &lt;/span&gt;
    &lt;p class="bodytext"&gt;To place an order, please enter the desired flavor from  
               the dropdown list:&lt;/p&gt;
    &lt;FORM name="drop_list" action="yourpage.php" method="POST" &gt;
        &lt;SELECT NAME="flavors_list" id="flavors_list"  
                    onchange="selectDropdown()"&gt;
        &lt;Option value="" &gt;Flavors List&lt;/option&gt;
        &lt;/SELECT&gt;
    &lt;/form&gt;
    &lt;div&gt;
    &lt;!--&lt;textarea id="shopping_cart" rows="5" cols="50"&gt;&lt;/textarea&gt;--&gt;
    &lt;table id="invoice"&gt;
    &lt;tr&gt;
        &lt;td width="150"&gt;&lt;textarea id="flavor_name" rows="10" cols="40" 
                     disabled="disabled" /&gt;&lt;/textarea&gt;&lt;/td&gt;
        &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;td id="calculator"&gt;
            &lt;label class="bodytext"&gt;Subtotal: &lt;/label&gt;&lt;input 
                                type="text" id="subtotal" size="10" disabled="disabled" 
                                  /&gt;&lt;br /&gt;
            &lt;label class="bodytext"&gt;Sales Tax: &lt;/label&gt;&lt;input 
                                 type="text" id="sales_tax" size="10" 
                                  disabled="disabled" /&gt;&lt;br /&gt;
            &lt;label class="bodytext"&gt;Total: &lt;/label&gt;&lt;input type="text" 
                                id="total" size="10" disabled="disabled" /&gt;&lt;br /&gt;
        &lt;/td&gt;

    &lt;/tr&gt;

    &lt;/table&gt;
           &lt;/body&gt;
           &lt;/html&gt;
</code></pre>

<p>Thanks in advance</p>
