Displaying total cost of prices from a table I have this JavaScript function which gets prices from a table, adds them up, and outputs the total cost. I want to refactor this to make it as small as possible.  

function getTotalPrice(do_request)
{
console.log('Get total price');
var prices_array = new Array(); // Where our prices are held

// For each .total_item_price - a &lt;td&gt; within my table.
$(".total_item_price").each(function(){
    var text = $(this).text();                   // Get the value
    var prices = text.substring(1, text.length); // Format it into a string
    prices_array.push(prices);                   // Push it onto our array
});

var result = eval(0);
//  Add up our array
for(i = 0; i &lt; prices_array.length; i++)
{
    temp = eval(prices_array[i]);
    result += temp;
}
// Round up our result to 2 Decimal Places
result = Math.round(result*100)/100;
// Output/Return our result
if (do_request == null)
{
    // We want to add our shipping Price and Display the total
    // Get the Shipping Price
    //var shipping_price = $(".shipping_price").html();
    //shipping_price = shipping_price.substring(1, shipping_price.length);
    if ($(".tbl_row").length == 1) // If only 1 row exists (How do I do this?)
    {
         var size = $(".size").html();
         if((size == "A5") &amp;&amp; ($('input[name="qty"]').val() == '1'))
         {
            console.log(' - A5 - ');
            $('.shipping_price').html('£0.67'); // Show Shipping Price (A5)
         }
         else if((size == 'A4') &amp;&amp; ($('input[name="qty"]').val() == '1'))
         {
            console.log(' - A4 - ');
            console.log($('input[name="qty"]').val());
            $('.shipping_price').html('£0.87'); // Show Shipping Price (A4)
         }
         else
         {
            console.log('More then 1 Qty');
            $('.shipping_price').html('£0.97'); // Show Shipping Price (A4) 
         }
    }
    else  // More then 1 row exists, so the price will be £0.97
    {
        console.log('false, More rows exists');
        $('.shipping_price').html('£0.97') // Show Shipping Price (A4)
    }

    var shipping_price = $(".shipping_price").html();
    shipping_price = shipping_price.substring(1, shipping_price.length);

    // Add em
    //result += eval(shipping_price);
    result += eval(shipping_price);

    // Round our result to 2 decimal places
    var result=Math.round(result*100)/100;

    // Update &amp; Display the Result
    $('.total_order_price').html("&lt;b&gt;£" + result + "&lt;/b&gt;");        
}
else 
{
    // Otherwise we just want the total price and return it.
    return result;
}
}
First, I would switch from using eval to parseFloat, since it appears that eval provides no extra features and allows arbitrary code to be executed unless you just happen to have values other then numbers in total_item_price tds. 

Second, since you are performing no extra processing with prices_array, it would be better to skip the array altogether and combine:

 var prices_array = new Array(); // Where our prices are held
 // For each .total_item_price - a &lt;td&gt; within my table.
 $(".total_item_price").each(function(){
     var text = $(this).text();                   // Get the value
     var prices = text.substring(1, text.length); // Format it into a string
     prices_array.push(prices);                   // Push it onto our array
 });

 var result = eval(0);
 //  Add up our array
 for(i = 0; i &lt; prices_array.length; i++)
 {
     temp = eval(prices_array[i]);
     result += temp;
 }


into (with result renamed as totalSum for readability):

 var totalSum = 0;
 // For each .total_item_price - a &lt;td&gt; within my table.
 $(".total_item_price").each(function(){
     var text = $(this).text();                   // Get the value
     var price  = text.substring(1, text.length); // Format it into a string
     price = parseFloat(price);
     totalSum += price;
 });