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

223
Views
Hacer que el botón desaparezca después de llegar a mi ruta

Quiero que mi usuario presione un botón para "asistir", luego muestre un "gracias" y elimine el botón.

Aquí está mi botón:

 <div class="col-6 offset-3"> <form action="/events/<%= event._id%>/guests" method="POST" novalidate class="needs-validation"> <div class="d-grid gap-2 col-6 mx-auto mb-2"> <button id="attendingBtn" onclick="buttonDisappear()" class="btn btn-primary mb-3">I'm attending</button> </div> </form> </div>

Cuando uso remove() en mi función (abajo), el botón desaparece después de hacer clic en él, pero no llega a la ruta ni envía datos a mi base de datos:

 function buttonDisappear() { document.getElementById("attendingBtn").remove(); }

Pero cuando uso style.display = none; el botón desaparece hasta que la página se vuelve a cargar y el botón vuelve.

 function buttonDisappear() { document.getElementById("attendingBtn").style.display = 'none'; }

Esto se debe a que tengo un res.redirect de regreso a la página en mi función (abajo).

 module.exports.addGuest = async (req, res) => { const event = await Event.findById(req.params.id); const guest = new Guest(req.body.guest); event.guests.push(guest); await guest.save(); await event.save(); res.redirect(`/events/${event._id}`); }

¿Cómo obtengo el botón para publicar datos y luego hago que la tarjeta muestre un "gracias" o simplemente hago que el botón desaparezca?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

  1. Cuando hace clic en el botón, almacene el identificador del cliente en la cookie/almacenamiento local
  2. Cuando cargue la página, verifique si hay una cookie, si está presente, botón ocultar
  3. Use Promises: addGuest debe devolver Promise y en su función buttonDisappear resuélvalo:
 addGuest(someArgs).then(() => { // save cookies // show card });
about 4 years ago · Santiago Gelvez 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!