Title: How can I get the alert box to show total from dropdown selections?
Tags: javascript;jquery
Question: I've made an error in this script and the alert box doesn't calculate the total, can anyone help please?
The alert box just shows 0 but I need it to total the value of the 2 dropdown selections

```<head&gt;
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;</script&gt;
<title&gt;Sandbox</title&gt;
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;
<style type="text/css" media="screen"&gt;
body { background-color: #fff; font: 16px Helvetica, Arial; color: #fff; }
</style&gt;
</head&gt;
<body&gt;
<select id="t_dermal_name"&gt;
<option value="t_default_dermal"&gt;-- Choose --</option&gt;
<option value="1" rel="30"&gt;Between Eyebrows</option&gt;
<option value="7" rel="30"&gt;Individual Line Softening</option&gt;
<option value="2" rel="30"&gt;Lip Contouring</option&gt;
</select&gt;
<select id="t_wrinkle_name"&gt;
<option value="t_default_wrinkle"&gt;-- Choose --</option&gt;
<option value="1" rel="30"&gt;Between Eyebrows</option&gt;
<option value="7" rel="30"&gt;Individual Line Softening</option&gt;
<option value="2" rel="30"&gt;Lip Contouring</option&gt;
</select&gt;
<br /&gt;
<button id="btn1"&gt;click</button&gt;
<script&gt;
 $(document).ready ( function () {
    $("#btn1").click ( function () {
      var resultVal = 0.0;
      var objRegExp = '\s+';
       $(".test").each ( function() {
            resultVal += parseFloat ( $(this).val().replace(/\s /g,'').replace(',','.'));
        });
        alert ( resultVal );  
    });
});

</script&gt;
<script src="/js/render/edit.js"&gt;</script&gt;
<script&gt;var _gaq=[['_setAccount','UA-1656750-13'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)})(document,'script')</script&gt;</body&gt;

</html&gt;
```



Here is another answer: ```$(".test").each```
Don't know if this is your only problem but... You don't have any elements with the class ```test``` so your code does nothing as the selector grabs nothing, so you stay with ```0```.

Maybe you meant:

```$("select").each (function() { ... // Will select all the select elements.
```

You can also simplify the code with:

```$("#btn1").click (function () {
    var resultVal = 0;
    $("select").each(function() {
        resultVal += parseFloat($(this).val());
    });
    alert (resultVal);  
});
```

Comment for this answer: just spotted this, got there before me!

Here is another answer: ```$("#btn1").click ( function () {
    var total = 0;

    $('select[id*="_name"]').each(function(){
        total += parseFloat($(this).val());
    });

    alert(total);
});
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:02/29/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery>', 'Title': 'How can I get the alert box to show total from dropdown selections?', 'ViewCount': 540, 'id': 9505271, 'user_AboutMe': None, 'user_AccountId': 1282489.0, 'user_DisplayName': 'user1236274', 'user_Reputation': 1.0, 'user_Views': 4.0, 'user_id': 1236274.0}}