Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
How send value from django html to django views

I want to make a section with goods in which you can "+" and "-" increase or decrease the quantity of goods And then, depending on the amount, "sell" it.

Now we need to pass the value {{ el.id }} to django views

My code: html:

    <form method="POST">
    {% csrf_token %}
    {% for el in form3 %}
    {% if el.count > 0 %}
           [ {{ el.count }}шт. ] <br>
           [ {{ el.title }} ]<br>
           <a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
           <span id="value{{ el.id }}">0</span>
            <a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
            <br>
Function where i + or - from count
<script>
$(function(){
    var valueElement = $('#value{{ el.id }}');
    function incrementValue(e){
        valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
        return false;

    }
    $('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
    $('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
});
</script>
            {% endif %}
            {% endfor %}
       </form>

how can i get the values with "span id=value{{ el.id }}"

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Solved

    {% for el in form3 %}
    {% if el.count > 0 %}
           [ {{ el.count }}шт. ] <br>
           [ {{ el.title }} ]<br>
           <a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
           <span id="span-value{{el.id}}">0</span>
           <a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
        <br>
                <input type="hidden" name=name-{{el.id}} id="input-{{el.id}}" value="0">
        <script>
            $(function(){
            var valueElement = $('#span-value{{el.id}}');
            function incrementValue(e){
            valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
    var value = $("#span-value{{el.id}}").text();
    var lower=$("#input-{{el.id}}").val(value);
            return false;
            }
                $('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
                $('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
            });
        </script>
    {% endif %}
    {% endfor %}

use this for copy\duplicate span value on input After this you can user request.post.dict or request.post.items() for key:values

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda