jquery - calculate percentage for each value
<p>I have a function that need to sum up from each input but at the same time every input must show the percentage. I have found the way to sum the value but I am having problem to show the percentage. Below is the HTML code:</p>

<pre><code>Price 1: &lt;input type="text" name="price01" class="price" /&gt;
Percentage 1: &lt;span class='p'&gt;&lt;/span&gt;
&lt;br/&gt;
Price 2: &lt;input type="text" name="price02" class="price" /&gt;
Percentage 2: &lt;span class='p'&gt;&lt;/span&gt;
&lt;br/&gt;
Price 3: &lt;input type="text" name="price03" class="price" /&gt;
Percentage 3: &lt;span class='p'&gt;&lt;/span&gt;
&lt;br/&gt;
Price 4: &lt;input type="text" name="price04" class="price" /&gt;
Percentage 4: &lt;span class='p'&gt;&lt;/span&gt;
&lt;br/&gt;
Total: &lt;span class="total"&gt;&lt;/span&gt;
</code></pre>

<p>The jquery code I found in internet:</p>

<pre><code>$.fn.sumValues = function() {
    var sum = 0;
    this.each(function() {
        if ( $(this).is(':input') ) {
            var val = $(this).val();
        } else {
            var val = $(this).text();
        }
        sum += parseFloat( ('0' + val).replace(/[^0-9-\.]/g, ''), 10);
    });
    return sum;
};

$(document).ready(function() {
    $('input.price').bind('keyup', function() {
        $('span.total').html( $('input.price').sumValues() );
    });
});
</code></pre>

<p>Hope anyone can help... Thank you.</p>

<hr>

<p>Thank you, guys. I think I have solved the problem. It may not be the best solution but I get the idea and it works. Thank you again :)</p>

<p>The solution code: <a href="http://jsfiddle.net/amaleen123/6jnKf/2/" rel="nofollow">http://jsfiddle.net/amaleen123/6jnKf/2/</a></p>
