Calculate sum for two values per radio button for a group of buttons with JS
<p>I have 4 groups of radio buttons and each group has 4 buttons. Each button has set two values separated with | i.e.:</p>

<pre><code>&lt;input type="radio" id="t20" name="train2" value="0|0"&gt;
&lt;input type="radio" id="t20" name="train2" value="5|0.19"&gt;
&lt;input type="radio" id="t20" name="train2" value="10|0.19"&gt;
&lt;input type="radio" id="t20" name="train2" value="15|0.19"&gt;
</code></pre>

<p>All 4 groups follow above example - different number for the first value, and same number for second value of buttons 2,3 and 4. From each group I have only 1 button checked.</p>

<p>I have a java script that has to make some calculations for the values of the checked buttons:</p>

<pre><code>$(document).ready(function()
{   
var total = 0;
function calcTotal()
{
    $("input:checked").each(function()
    {
        var value = $(this).attr("value");
        var array = value.split('|')
        var firstValue = array[0];
        var secondValue = array[1];
        total += parseFloat(firstValue);
    });
}
calcTotal();
$("sum").before('&lt;font class="total" style="font-family: Myriad Pro, Gill Sans, Gill Sans MT, Calibri, sans-serif; font-size: 18px; font-weight: bold;"&gt;' + total + '&lt;/font&gt;');
});
</code></pre>

<p>The result for the sum of the first values for the checked radio buttons is OK. The updated some if you change some of the selection also. </p>

<p>What I can not do properly is to calculate the sum for the second values and output them at the same manner. I've been trying for a day with no luck.</p>

<p><strong>NOTE</strong> I need the sums ONLY for the checked buttons. But I need one sum of the first values and another sum of the second once</p>

<p><strong>NOTE2</strong> In each group I have checked ONLY 1 button, this is why I need <code>$("input:checked").each(function()</code> so it is not the sum from 4 buttons in 1 group.</p>

<p><strong>NOTE3</strong> full code <a href="http://jsfiddle.net/P3ZyH/10/" rel="nofollow">http://jsfiddle.net/P3ZyH/10/</a></p>

<p>Any help highly appreciated.</p>

<hr />

<p>Finally I found what's wrong ... it was very hard to stop me brak through the wall with my head.</p>

<p>There is last group of 2 rafio buttons and I forgot to assign their second value. SO now all is working OK.</p>

<p>If anyone is interested - <a href="http://jsfiddle.net/milenmk/P3ZyH/17/" rel="nofollow">http://jsfiddle.net/milenmk/P3ZyH/17/</a></p>
