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

98
Vistas
Hola, estoy trabajando con HTML y JavaScript tratando de trabajar en los botones aprobar/denegar

Tengo dos botones al lado de los datos que la pantalla mostrará para aprobar o denegar. Estoy tratando de averiguar cómo hacerlo para que cuando el usuario haga clic en aprobar, la columna Estado cambie de pendiente a aprobado y lo mismo para denegar. aquí está la parte JS

 let getAllbtn = document.getElementById("getAllbtn"); let Approve = document.getElementById("Approve"); let Deny = document.getElementById("Deny"); getAllbtn.addEventListener("click", getAllReimbursements); Approve.addEventListener("click", approveReimb); Deny.addEventListener("click", denyReimb);

y aquí está la parte html

 <body> <button id="btn" id="getAllbtn">Get All Reimbursements</button> <br> <table class="table" id="table"> <thead> <tr> <th>Id</th> <th>Amount</th> <th>Submitted</th> <th>Resolved</th> <th>Description</th> <th>AuthorId</th> <th>ResolverId</th> <th>Type</th> <th>Status</th> <th>Approve</th> <th>Deny</th> </tr> </thead> <tbody id="tbody"> <tr> <td>1</td> <td>0</td> <td>0</td> <td>0</td> <td>hotel</td> <td>2</td> <td>1</td> <td>TRAVEL</td> <td>PENDING</td> <td><button id="btn" id ="Approve">X</button></td> <td><button id="btn" id ="Deny">X</button></td> </tr> </tbody> </table>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Puedes simplificar esto mucho

  1. establecer un nombre de clase en el TD que desea actualizar (le di una clase de 'estado')
  2. hacer que Aprobar y Denegar use la misma función que solo lee un data-attribute para establecer el estado
  3. use el closest() junto con querySelector para apuntar al TD en cuestión

 document.querySelectorAll('.status-btn').forEach(button => { button.addEventListener("click", e => { e.target.closest('tr').querySelector('td.status').innerText = e.target.dataset.status; }); });
 <table class="table" id="table"> <thead> <tr> <th>Id</th> <th>Amount</th> <th>Submitted</th> <th>Resolved</th> <th>Description</th> <th>AuthorId</th> <th>ResolverId</th> <th>Type</th> <th>Status</th> <th>Approve</th> <th>Deny</th> </tr> </thead> <tbody id="tbody"> <tr> <td>1</td> <td>0</td> <td>0</td> <td>0</td> <td>hotel</td> <td>2</td> <td>1</td> <td>TRAVEL</td> <td class='status'>PENDING</td> <td><button class="btn status-btn" data-status="Approved">X</button></td> <td><button class="btn status-btn" data-status="Denied">X</button></td> </tr> </tbody> </table>

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