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

120
Vistas
Read data from dynamically generated forms with Javascript

so ive an HTML page that have multiple generated forms:

{% for row in data %}
    <form action="/aggiorna_pratica" method='POST' id="inserisci_app_{{ row[0][1] }}">
       <input name="id_pratica_{{ row[0][1] }}" type='hidden 'id="id_pratica_{{ row[0][1] }}" value="{{ row[0][1] }}"></input> 

       <button type="submit" class="btn btn-success aggiorna_app">
          <i class="fa fa-check"></i>
       </button>
    </form>
{% endfor %}

row[0][1] contains the id of the row.

Im trying to send ajax requests from every single one of them, but i get the same ID of the frist row from every row.

This is the Javascript

$(document).ready(function() { $(".aggiorna_app").click(function(event) { 
//prevent submit
event.preventDefault(); //Thx @alex

//do things on submit
$.ajax({
    data : {
        tipo_richiesta : "inserisci_intervento",
        id : $('#id_pratica').val(),
        data_int : $('#data_int').val(),
        ora_int : $('#ora_int').val()
    },
    type: "POST",
    url: "/aggiorna_pratica",
    beforeSend: function(){
        //Before send data
    },
    success: function(data){
        console.log(data);
    }
});

}); });

I know im a newbie but i could really use some help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is a working example to test your click event. The click event is on .aggoriorna_app buttons inside each form, but the id being passed into the ajax call looks to be grabbing the .val() every time, e.g, $('#id_pratica').val(). You'll see in my example that when a button is clicked, find the nearest input value and set the ajax id to that value. I assume that's what you need.

$(document).ready(function() { 
        $(".aggiorna_app").click(function(event) { 
            //prevent submit
            event.preventDefault(); //Thx @alex
    
            var id = $(this).parent().find('input').val();
            alert(id);
        });
    });
form {
  margin-bottom: 3rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
    <form action="/aggiorna_pratica" method='POST' id="inserisci_app_{{ row[0][1] }}">
        <input name="id_pratica_{{ row[0][1] }}" type='hidden 'id="id_pratica_1" value="input_1"></input> 
        <button type="submit" class="btn btn-success aggiorna_app">
            <i class="fa fa-check"></i>CLICK ME
        </button>
    </form>
    <form action="/aggiorna_pratica" method='POST' id="inserisci_app_{{ row[0][1] }}">
        <input name="id_pratica_{{ row[0][1] }}" type='hidden 'id="id_pratica_2" value="input_2"></input> 
        <button type="submit" class="btn btn-success aggiorna_app">
            <i class="fa fa-check"></i>CLICK ME
        </button>
    </form>
    <form action="/aggiorna_pratica" method='POST' id="inserisci_app_{{ row[0][1] }}">
        <input name="id_pratica_{{ row[0][1] }}" type='hidden 'id="id_pratica_3" value="input_3"></input> 
        <button type="submit" class="btn btn-success aggiorna_app">
            <i class="fa fa-check"></i>CLICK ME
        </button>
    </form>
</div>

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