title: Get total value by Javascript in laravel 5.5
body: <p>I try to get shipment price sum to my cart total price by ajax.</p>
  <p>What I have so far:</p>
  <ol>
  <li>Getting total price of cart.</li>
  <li>Getting price list of shipping methods.</li>
  </ol>
  <p>What I want to do is to <code>sum</code> this 2 values together.</p>
  <p><strong>example:</strong></p>
  <p><code>Cart Total:</code> 20.000
  <code>Shipping Cost:</code> 10.000</p>
  <p><code>Total:</code> 30.000</p>
  <h1>My Codes</h1>
  <p><strong>Controller:</strong></p>
  <pre><code>//Select shipping method to sum with total price of cart
      public function totalPriceInTotal(Request $request, $postchoose) {
        $totalPriceIn = $request-&gt;input('postchoose');
        return response()-&gt;json($totalPriceIn);
      }
  </code></pre>
  <p><strong>Route:</strong></p>
  <pre><code>Route::get('/totalPriceInTotal/{postchoose}','CartController@totalPriceInTotal');
  </code></pre>
  <p><strong>View:</strong></p>
  <pre><code>//HTML
  &lt;div class=&quot;panel-body&quot; id=&quot;totalPriceInTotal&quot;&gt;
  
  &lt;/div&gt;
  
  
  //JavaScript
  &lt;script&gt;
    $(document).ready(function() {
      $('select[name=&quot;postchoose&quot;]').on('change', function() {
        var destinationPrice = $(this).val();
        if(destinationPrice) {
        $.ajax({
          url: '{{ url('totalPriceInTotal') }}/'+encodeURI(destinationPrice),
          type: &quot;GET&quot;,
          dataType: &quot;json&quot;,
          success:function(data) {
            $('#totalPriceInTotal').empty();
            $('#totalPriceInTotal').append('&lt;p&gt;' + {{Cart::getTotal()}} + $totalPriceIn + '&lt;/p&gt;');
          }
        });
        }else{
          $('#totalPriceInTotal').empty();
        }
      });
    });
  &lt;/script&gt;
  </code></pre>
  <p><strong>My Network Result:</strong></p>
  <p><a href="https://i.stack.imgur.com/4csKG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4csKG.jpg" alt="screen1" /></a></p>
  <blockquote>
  <p>PS: <strong>All I need is to <code>sum</code> that <code>37000</code> with my cart total price</strong>.</p>
  </blockquote>
  <h1>UPDATE:</h1>
  <p>this how I get my shipping data on dropdown and select that <code>37000</code> from it:</p>
  <pre><code>success:function(data) {
                  $('#des').empty();
                  $('#des').append(
                    '&lt;p&gt;Destination: ' + data['meta']['destination']['province'] + ' , ' + data['meta']['destination']['type'] + ' , ' + data['meta']['destination']['city_name'] + ' , ' + data['meta']['destination']['postal_code'] +'&lt;/p&gt;'
                    );
                  $.each(data.data, function(key, value) {
                    $('#info').empty();
                    $('select[name=&quot;postchoose&quot;]').empty();
                    $('#info').append('&lt;h3&gt;'+ value['code'] + '&lt;small&gt;' + value['name'] +'&lt;/small&gt;&lt;/h3&gt;');
                      $.each(value.costs, function(key2, value2) {
                        $.each(value2.cost, function(key3, value3) {
  
                          // number format
                          var number = value3['value'];
                          var nf = new Intl.NumberFormat('en-US', {
                              maximumFractionDigits:0, 
                              minimumFractionDigits:0
                          });
  
                          var formattedNumber = nf.format(number);
                          // number format
                          $('select[name=&quot;postchoose&quot;]').append('&lt;option id=&quot;postchoose&quot; class=&quot;form-control&quot; name=&quot;postchoose&quot; value=&quot;'+ value3['value'] +'&quot;&gt;'+ value2['service'] + ' - ' + nf.format(number) + ' Rp' + ' - ' + value3['etd'] + ' hari' +'&lt;/option&gt;');
                        });
                      });
                  });
                }
  </code></pre>