Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
actualizar datos al hacer clic en un botón en cada fila

Soy un programador novato. Necesito seleccionar y luego actualizar los datos cuando hago clic en un botón en cada fila. ahora puedo seleccionar y mostrar datos, pero solo funciona el primer botón de actualización. Creo que la causa de este problema es que la identificación del botón es la misma. No puedo entender cómo crear una identificación única. Intento cambiar id="updatedb" a id="$i" y nada funciona

mi guión es:

 $(function(){ $('#updatedb').click(function(){ var a = $('#updatedb').attr('id'); $('#textstatus').val(a); alert ($('#updatedb').attr('id')); }); });

y php es:

 $sql = $connectdb->query($checknode); $i = 0; echo "<table border=1>"; if (!$sql) { echo $connectdb->error; else { while ($row=$sql->fetch_row()) { $crow = "updatedb".$i; //echo $crow."<br />"; echo "<form method='post' action=''>"; echo '<tr><td>'.$row[0].' </td><td>'.$row[1].'</td><td>'.$row[2].' </td><td>'.$row[3].'</td><td>'.$row[4].' </td><td>'.$row[5].'</td><td> <input type="button" id="updatedb" name="updatedb" value="update"> <input type="text" id="textstatus" name="textstatus" value="" disabled="disabled"></td></tr>'; $i++; } } echo "</form>"; echo "</table>";
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar la clase en lugar de la identificación para el botón para actualizar, vea el código a continuación

jquery

 $(function(){ $('.updatedb').click(function(){ var a = $(this).attr('class'); $(this).parents('tr').find('.textstatus').val(a); alert (a); }); });

php

 $sql = $connectdb->query($checknode); $i = 0; echo "<table border=1>"; if (!$sql) { echo $connectdb->error; }else { while ($row=$sql->fetch_row()) { $crow = "updatedb".$i; //echo $crow."<br />"; echo "<form method='post' action=''>"; echo '<tr><td>'.$row[0].' </td><td>'.$row[1].'</td><td>'.$row[2].' </td><td>'.$row[3].'</td><td>'.$row[4].' </td><td>'.$row[5].'</td><td> <input type="button" class="updatedb" name="updatedb" value="update"> <input type="text" class="textstatus" name="textstatus" value="" disabled="disabled"></td></tr>'; $i++; } } echo "</form>"; echo "</table>";
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!