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, enter image description here

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

$  variables = array(         'order' => $  order,         'contents_view' => commerce_embed_view('commerce_cart_block', 'defaults', array($  order->order_id), $  _GET['q']),       );       $  count = commerce_line_items_quantity($  wrapper->commerce_line_items, commerce_product_line_item_types());        $  quantity = 0;        foreach ($  wrapper->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->type->value(), $  types)) {           $  quantity = $  quantity + $  line_item->quantity->value();          }       }        $  prod_count = t($  quantity);          if ($  prod_count > 0){          $  icon = '<div class="cart-icon"></div><span class="cart_popup_count">'. $  count . '</span>';         $  content = '<div id="cart-popup" style="display:none;">' . theme('commerce_cart_block', $  variables) . '<div class="popup-arrow"></div></div>';         $  content = '<div class="wrapper">' . $  icon . $  content . '</div>';         }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", "<div class='cart-contents'></div>");   $  commands[] = ajax_command_html('#block-commerce-popup-cart-commerce-popup-cart .cart-contents', $  res);   return array('#type' => 'ajax', '#commands' => $  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->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; } 

New Year Chaos JavaScript, needs to be sped up

Similar to this question but this is for python

Original problem with description on hacker rank

I am currently trying to iterate through large number arrays and count how many times numbers have been swapped. A sorted array looks like this: [1,2,3,4,5] and a number can be swapped only towards the front (counting down to 0) twice.

If a number is more than 2 out of order the array is deemed ‘Too chaotic’ and the process should stop.

Instead of bubble sorting i am simply going through and counting the actual swaps as a sorted array is not actually required, my code works except for a couple of the tests where it times out due to large arrays.

Any ideas on how to speed this process up?

function minimumBribes(q) { console.log(sort(q));      function sort(items) {      let bribes = 0;       for (let i = 0; i < items.length; i++) {          if (items[i] - (i + 1) > 2) return "Too chaotic";          for (let j = 0; j < i; j++) {              if (items[j] > items[i]) bribes++;          }      }       return bribes;    } } 

Сброс значений калькулятора при клике javascript

var ah = {   40: 8,   45: 10,   50: 11,   55: 12,   60: 14,   65: 15,   70: 16,   75: 16,   85: 17,   90: 18,   95: 19,   100: 20,   110: 21,   120: 25,   132: 30,   140: 32,   190: 42,   200: 44,   210: 46,   220: 48,   230: 50,  }  $  (document).ready(function() {  function calcTotal() {     $  ('#res1').html('');     var op = $  ("#select-ah").val();     var op1 = +ah[op];     var v = +$  ("#val1").val();     var total = op1 * v;     var total2 = op1 * 0 * v;     var sbros = $  (#reset1).click(function(){     return total2; }; //console.log(op, op1, v, total); if (!isNaN(total)) {   $  ('#res1').append($  ("<span></span>").text(total)); }; else if (!isNaN(total2)) {   $  ('#res1').append($  ("<span></span>").text(total)); }; else {       $  ('#res1').html('<span>Результат</span>');     } }    $  ('#minus').click(function() {     var $  input = $  (this).parent().find('input');     var count = +$  input.val();     if (isNaN(count))       count = 0;     count--;     count = count < 1 ? 1 : count;     $  input.val(count);     $  input.change();   });   $  ('#plus').click(function() {     var $  input = $  (this).parent().find('input');     var count = +$  input.val();     if (isNaN(count))       count = 0;     count++;     $  input.val(count);     $  input.change();   });      Object.keys(ah).forEach((item) => {     $  ('#select-ah').append('<option value="' + item + '">' + item + '</option>');   });      $  ('#select-ah').change(calcTotal);   $  (".block__val input").change(calcTotal); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="select-ah">   <option>Выберите емкость (A/ч)</option> </select> </div> <div class="block__val" style="display:flex;justify-content: center;width:35%;">   <span class="btn-btn1" id="minus">-</span>   <input type="text" value="1" style="text-align: center;border-radius: 0px;" id="val1">   <span class="btn-btn1" id="plus">+</span> </div> </div> <div class="price-itog">   <p style="margin-top: 47px; color:#2E0648;">Стоимость: <span id="res1"></span></p> </div>

¿Enviar JSON método POST javascript firebase function?

estoy intentando enviar un POST a una función en firebase. Desde postman funciona, pero desde javascript(jquery) solo logro enviarlo como texto plano y se almacena de forma incorrecta en la base de datos de firebase. Intenté convirtiendo usando JSON.stringify pero no funciona, ni siquiera retorna un error. Código ejemplo en el que me estoy basando

     var arr = { City: 'Moscow', Age: 25 }; $  .ajax(   {        url: "https://url",        method: "POST",        data: JSON.stringify(arr),        contentType: "application/json"   }); 

y al pasarlo como texto plano, en la base de datos queda así: introducir la descripción de la imagen aquí

Vuelvo a indicar que desde POSTMAN se inserta correctamente enviandolo como JSON Agradezco cualquier solución así sea usando el objeto request.

Magento 2.3.1 not loading correct javascript files (tinymce)

I’ve upgraded from Magento 2.2.6 with Theme Ves Fresh 2. I have tried to clean all caches delete static folder and restart Varnish, but had no luck so far.

The errors include:

GET https://shop.xxxxs.de/static/adminhtml/Magento/backend/en_US/tinymce.js net::ERR_ABORTED 404 (Not Found)

http://requirejs.org/docs/errors.html#scripterror     at makeError (require.js:166)     at HTMLScriptElement.onScriptError   GET https://shop.xyxxyx.de/static/adminhtml/Magento/backend/en_US/themes/modern/theme.js net::ERR_ABORTED 404 (Not Found) ```   Uncaught TypeError: b is not a constructor     at m (tinymce.min.js:13)     at Object.q [as init] (tinymce.min.js:13)     at p.<anonymous> (tinymce.min.js:13)     at Array.<anonymous> (tinymce.min.js:4)     at b (tinymce.min.js:2)     at r (tinymce.min.js:4)     at tinymce.min.js:4     at HTMLScriptElement.h (tinymce.min.js:4) 

Errors

Dúvida ao chamar função em JavaScript – uso de parenteses

Estou estudando um pouco de JavaScript, e me deparei com uma situação que não entendi muito bem. O autor cria uma função e quando vai chamá-la pelo método onclick ele não coloca os parentes da função…

        function mostrarAlerta(){             alert("Hello World!");         }          var botao = document.querySelector("button");         botao.onclick = mostrarAlerta; 

ou seja, ” botao.onclick = mostrarAlerta;” nesse mostrarAlerta não deveria vir os parenteses? tipo botao.onclick = mostrarAlerta()?

Javascript not working in IE but work works in Chrome

I had a long search and until I found a working script to use the logged in user id. Finally I have found the following Javascript code, put it in XSL to be used in an XMl viewer web part:

<script language="javascript" defer="true">       <xsl:comment>         <![CDATA[  ExecuteOrDelayUntilScriptLoaded(init,'sp.js'); var currentUser; function init(){     this.clientContext = new SP.ClientContext.get_current();     this.oWeb = clientContext.get_web();     currentUser = this.oWeb.get_currentUser();     this.clientContext.load(currentUser);     this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed)); }  function onQuerySucceeded() { }  function onQueryFailed(sender, args) {     alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace()); }          ]]>       </xsl:comment>     </script> 

I call the function like this:

<A class="bluelink" href = "javascript:void(0)" onclick="javascript:window.location='{$  mailtolink}' + '%0D%0Auserid: ' + currentUser.get_loginName() + '%0D%0Aurl: ' +  window.location; return false;">Request additional rights</A> 

The mailtolink variable represents a valid mailto: link. The problem is, that in IE11 (also in IE8 compatibility mode), the mail body ends only with

userid: i:0

However in Chrome, I get all the details I need:

userid: i:0#.w|tdomain\testuser
url: https://myserver/testsite/default.aspx

I made the mail body shorter, to make sure it is not the lenght, but I got the same results. Can someone give me a hint how to make the script work in IE?