how to update quantity of products in the cart via javascript? I have the module that changes the quantity of products inside the card via ajax but I need to change it also outside, as on the picture, 

the code that changes the quantity after reload of the page are as follows

$variables = array(
        'order' =&gt; $order,
        'contents_view' =&gt; commerce_embed_view('commerce_cart_block', 'defaults', array($order-&gt;order_id), $_GET['q']),
      );
      $count = commerce_line_items_quantity($wrapper-&gt;commerce_line_items, commerce_product_line_item_types());

      $quantity = 0;

      foreach ($wrapper-&gt;commerce_line_items as $line_item) {
        if (!$line_item instanceof EntityMetadataWrapper) {
          $line_item = entity_metadata_wrapper('commerce_line_item', $line_item);
        }
        $types = array('product');

        if (empty($types) || in_array($line_item-&gt;type-&gt;value(), $types)) {
          $quantity = $quantity + $line_item-&gt;quantity-&gt;value();

        }
      }

      $prod_count = t($quantity);  

      if ($prod_count &gt; 0){

        $icon = '&lt;div class="cart-icon"&gt;&lt;/div&gt;&lt;span class="cart_popup_count"&gt;'. $count . '&lt;/span&gt;';
        $content = '&lt;div id="cart-popup" style="display:none;"&gt;' . theme('commerce_cart_block', $variables) . '&lt;div class="popup-arrow"&gt;&lt;/div&gt;&lt;/div&gt;';
        $content = '&lt;div class="wrapper"&gt;' . $icon . $content . '&lt;/div&gt;';  
      }elseif (variable_get('commerce_popup_cart_show_empty_cart', 0) == 1){
        $content = commerce_popup_cart_block_view_get_empty_cart($variables);
      }


The problem is that I don't know how to changes this numbers simultaneously inside and outside the card.

This is the code that changes quantity inside the card

  function _commerce_popup_cart_add_to_cart_ajax_callback($form, $form_state) {
  commerce_cart_add_to_cart_form_submit($form, $form_state); //Call the add to cart form to actually add the product
  $res = _commerce_popup_cart_ajax_cart_reload(); //Retrieve the new cart view

  $commands = array();
  $commands[] = ajax_command_replace("#block-commerce-popup-cart-commerce-popup-cart .cart-empty-block", "&lt;div class='cart-contents'&gt;&lt;/div&gt;");
  $commands[] = ajax_command_html('#block-commerce-popup-cart-commerce-popup-cart .cart-contents', $res);
  return array('#type' =&gt; 'ajax', '#commands' =&gt; $commands); 
}

function _commerce_popup_cart_ajax_cart_reload() {
  global $user;
  $view_name = 'commerce_cart_block'; // The name of the view we are going to load commerce_cart_block
  $args = array(commerce_cart_order_id($user-&gt;uid));  // Array of arguments we set for the view. Only one argument in our example. your actual view may require additional 

  //arguments which you may need to set   
  $displayId = 'default'; // The display id of for the view.
  // Call the views_embed_view function to returned themed view output
  $res = views_embed_view($view_name, $displayId, $args);
  return $res;
}
Create new simple module like my_updater_card
add hook_menu 
add php function to update the card 
call this function from ajax

&lt;?php
/**
 * Implements hook_menu().
 * see hook_menu()
 * see menu_example
 */
function my_updater_card_menu()
{
    $items['my_updater/card/%'] = array(
        'page callback'         =&gt; 'my_updater',
        'page arguments'        =&gt; array(2),
        'access arguments'      =&gt; array('put your permission here'),
    );
    return $items;
}

function my_updater($newTotal){
    //check if this request come from ajax =&gt; if not =&gt; ignore it
    //here put your php code to update the card
    //then return results true/false to ajax caller
}
?&gt;



Ajax

        $.ajax({
               url: 'my_updater/card/[new total here]',
               type: "GET",
               success: function (data) {
                 //do total refresh here 
               }
        });