javascript - Count prices inside the Django Inline -


i'm looking way count prices django (dynamic) inline using javascript.

i have scenario (inside django admin): enter image description here

and trying that:

{% block extrajs %}      <script type="text/javascript">          var subtotal = 0.00;          $('.field-product_code select').change(function(){              $('.related-widget-wrapper select').each(function(){                  product = $(this + 'option:selected').text();                  select_val = $(this).val();                  var regex = /[+-]?\d+(\.\d+)?/g;                    var str = product;                  var floats = str.match(regex).map(function(v) { return parsefloat(v); });                  var price = floats[0] * 1;                  console.log($(this).val());              });  //            row_id = $(this).closest('tr').attr('id');  //            console.log($(row_id).find('.price_product'));  {#            if(row_id + ' .price_product'){#}  {#                console.log('existe ja');#}  {##}  {#            }else {#}  {#                //$(this).append("<div class='price'>aa"+ product +"</div>");#}  {#                var regex = /[+-]?\d+(\.\d+)?/g;#}  {##}  {#                var str = product;#}  {#                var floats = str.match(regex).map(function(v) { return parsefloat(v); });#}  {#                var price = floats[0] * 1;#}  {#                console.log(price);#}  {#            }#}      {#            subtotal += price;#}  {#            console.log(subtotal);#}  {#            $('#total').html(subtotal);#}          })      </script>  {% endblock %}
<!-- inline html extracted inspector -->  <table class="table table-bordered table-condensed table-striped">  <thead><tr>      <th colspan="1" class="required">código produto      </th>      <th>quantidade      </th>      <th>apagar?</th>      </tr></thead>    <tbody>      <tr class="form-row  dynamic-movementcart_set row1" id="movementcart_set-0">          <td class="field-product_code">              <input id="id_movementcart_set-0-id" name="movementcart_set-0-id" type="hidden">              <input id="id_movementcart_set-0-movement" name="movementcart_set-0-movement" type="hidden">              <div class="related-widget-wrapper">                  <select id="id_movementcart_set-0-product_code" name="movementcart_set-0-product_code">                      <option value="" selected="selected">---------</option>                      <option value="8888">Água mineral - r$ 0.69</option>                      <option value="9999">coca-cola lata - r$ 1.99</option>                      <option value="7891027114626">vodka - r$ 20.0</option>                  </select>                  <a class="related-widget-wrapper-link change-related" id="change_id_movementcart_set-0-product_code" data-href-template="/painel/engine/product/__fk__/?_to_field=product_code&amp;_popup=1" title="alterar produto selecionado" href="/painel/engine/product/8888/?_to_field=product_code&amp;_popup=1">                      <img src="/static/admin/img/icon_changelink.gif" width="10" height="10" alt="modificar">                  </a>                  <a class="related-widget-wrapper-link add-related" id="add_id_movementcart_set-0-product_code" href="/painel/engine/product/add/?_to_field=product_code&amp;_popup=1" title="adicionar outro produto">                      <img src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="adicionar">                  </a>              </div>          </td>          <td class="field-qtde">              <p>1</p>          </td>          <td class="delete"></td>      </tr>      <tr class="form-row dynamic-movementcart_set row2" id="movementcart_set-1">            <td class="field-product_code">                  <input id="id_movementcart_set-1-id" name="movementcart_set-1-id" type="hidden">              <input id="id_movementcart_set-1-movement" name="movementcart_set-1-movement" type="hidden">                            <div class="related-widget-wrapper">                  <select id="id_movementcart_set-1-product_code" name="movementcart_set-1-product_code">                      <option value="" selected="selected">---------</option>                      <option value="8888">Água mineral - r$ 0.69</option>                      <option value="9999">coca-cola lata - r$ 1.99</option>                      <option value="7891027114626">vodka - r$ 20.0</option>                  </select>                      <a class="related-widget-wrapper-link change-related" id="change_id_movementcart_set-1-product_code" data-href-template="/painel/engine/product/__fk__/?_to_field=product_code&amp;_popup=1" title="alterar produto selecionado" href="/painel/engine/product/9999/?_to_field=product_code&amp;_popup=1">                      <img src="/static/admin/img/icon_changelink.gif" width="10" height="10" alt="modificar">                  </a>                      <a class="related-widget-wrapper-link add-related" id="add_id_movementcart_set-1-product_code" href="/painel/engine/product/add/?_to_field=product_code&amp;_popup=1" title="adicionar outro produto">                      <img src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="adicionar">                  </a>                    </div>                </td>                <td class="field-qtde">                        <p>1</p>              </td>            <td class="delete"><div><a class="inline-deletelink" href="javascript:void(0)">remover</a></div></td>      </tr><tr class="form-row  empty-form row1" id="movementcart_set-empty">      <td class="field-product_code">            <input id="id_movementcart_set-__prefix__-id" name="movementcart_set-__prefix__-id" type="hidden">          <input id="id_movementcart_set-__prefix__-movement" name="movementcart_set-__prefix__-movement" type="hidden">            <div class="related-widget-wrapper">              <select id="id_movementcart_set-__prefix__-product_code" name="movementcart_set-__prefix__-product_code">                  <option value="" selected="selected">---------</option>                  <option value="8888">Água mineral - r$ 0.69</option>                  <option value="9999">coca-cola lata - r$ 1.99</option>                  <option value="7891027114626">vodka - r$ 20.0</option>              </select>                  <a class="related-widget-wrapper-link change-related" id="change_id_movementcart_set-__prefix__-product_code" data-href-template="/painel/engine/product/__fk__/?_to_field=product_code&amp;_popup=1" title="alterar produto selecionado">                  <img src="/static/admin/img/icon_changelink.gif" width="10" height="10" alt="modificar">              </a>                  <a class="related-widget-wrapper-link add-related" id="add_id_movementcart_set-__prefix__-product_code" href="/painel/engine/product/add/?_to_field=product_code&amp;_popup=1" title="adicionar outro produto">                  <img src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="adicionar">              </a>            </div>        </td>        <td class="field-qtde">            <p>1</p>        </td>        <td class="delete"></td>      </tr>        <tr class="add-row"><td colspan="3"><a href="javascript:void(0)">adicionar outro(a) item</a></td></tr></tbody>  </table>

maybe i'll have 'count' #id_movementcart_set-0-id, #id_movementcart_set-1-id, #id_movementcart_set-2-id , subsequents, how can that?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -