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

89
Visualizações
how to make js function that specific to individual dynamic id

first of all, sorry for my bad english; secondly, iam really new with javascript, like know the concept but not have the full grip of the syntax; thirdly, the real problem is, i have idea to make a table that fetch data from database, and in the last column is an action button to show the detail of the row that been clicked, generating from database with ajax.

this my php code:

<?php $i=0; 
while($data=$query->fetch_assoc()){
    $i++;
    echo "<tr>";
    echo "<form action='' method='POST' id='show".$i."' role='form'>";
    echo "<td>"."<button type='submit' id='numb".$i."' value=".$data['num'].">";
    echo "detail</button></td>";
    echo "</form>";
    echo "</tr>";
}?> 

and this is my script:

<script> 
$(document).ready(function() {
  var len = $('[id^=show]').length;
  for (var i = 1; i <= len; i++) {
    var nn = "#numb" + i;
    $("#show" + i).submit(function(e) {
      e.preventDefault();
      $.ajax({
        type: "POST",
        url: "test.php",
        data: {
          numb: $(nn).val()
        },
        dataType: "html",
        success: function(response) {
          $("#container").html(response);
        }
      });
    });
  };
});
</script>

what iam trying is make multiple form with id like show, and count it in javascript, and then make function based on the how many id show in the table. but this code doesn't work, every detail button i click only return one data from the last parameter in the table. not data from the according row

about 4 years ago · Juan Pablo Isaza
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