Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda