Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:21:26+00:00 2026-05-24T16:21:26+00:00

I have this javascript, jquery function, (below) It gets the text inside each table

  • 0

I have this javascript, jquery function, (below)

  1. It gets the text inside each table cell (of class=”total_item_price”) of a table.
  2. It puts it into an array (prices_array)
  3. Adds up prices_array and formats them to 2 Decimal Places.
  4. Then outputs it into the total_order_price, or returns it if do_request isset.

Problem: I have a function that deletes a item from the basket, then calls this function (getTotalPrice) to update the prices field. This part does not work correctly, and is not producing the correct price.

Basically, I need this function, to:

  • Get the price(s) of (.total_item_price) which is inside a cell.
  • Get the shipping price (.shipping_price) + Add them all up
  • Display it inside cell (.total_order_price)

Then When I call my delete function, I can call ^this^ function to hopefully update the price correctly.
I also call this getTotalPrice function on DOM Ready to update the prices, so its important it works correctly, It also has to work when I call my delete function (below).

I have a jsfiddle but it doesn’t work, but this code does work on my localhost. I had to compact it for jsfiddle, and its broken somewhere. Feel free to edit how you want.


Here Is the Code(!):
This function gets the total price and displays it.

function getTotalPrice(do_request)
{
var prices_array = new Array(); // Where our prices are held 

// For each .total_item_price - a <td> within my table.
$(".total_item_price").each(function(e){
    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 < 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);

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

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

    // Update & Display the Result
    $('.total_order_price').html("<b>£" + result + "</b>");        
}
else 
{
    // Otherwise we just want the total price and return it.
    return result;
}
}

This is the function I made to delete a row from the table and update the prices.

// Delete Item from Basket, Run on click of delete button
function delete_item(e)
{
doIt = confirm('Delete Item from Basket?\r\n You can not undo this action.');
if(doIt)
{
  // Get our basket
  var basket_md5 = $(e).parent().find("input[name='basket_md5']").val();
  var url = "<?php echo SERVER_URL."shop/basket"; ?>";
  // Post to basket
  $.post(url, { "do": "delete_item","basket_md5": basket_md5});

  // Delete Row from Table
  // Row Scope
  var row = $(e).parent().parent();

  // Effect & Remove from DOM
  $(row).fadeOut(1000, function(){ 
      $(this).remove();

  });

  // Update the Prices (again)
  //tprice = getTotalPrice("return");
  //$('.total_order_price').html("<b>£" + tprice + "</b>"); 
  getTotalPrice();
 }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:21:27+00:00Added an answer on May 24, 2026 at 4:21 pm

    In function delete_item(e) move ‘getTotalPrice(); here:

    $(row).fadeOut(1000, function(){ 
          $(this).remove();
          // Update the Prices (again)
          //tprice = getTotalPrice("return");
         //$('.total_order_price').html("<b>£" + tprice + "</b>"); 
         getTotalPrice();
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have this javascript code below that uses jquery, it is suppoed to be
I have the following Javascript/jQuery function: function addEventHandler(){ $(div).mouseenter(function() { $(this).html(Over); }).mouseleave(function() { $(this).html(Out);
I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
I have this function in my Javascript Code that updates html fields with their
I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
Javascript and jQuery (Fancybox) question I'm using the Javascript function below for Twitter sharing
I have what i thought was a simple javascript / jquery function (fade out
Possible Duplicates: How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.