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

232
Visualizações
Make button disappear after hitting my route

I want my user to press a button to "attend" then show a "thank you" and remove the button.

Here's my button:

    <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>

When I use remove() in my function (below) the button disappears after it's clicked but doesn't hit the route or send data to my db:

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

But when I use style.display = none; the button disappears until the page reloads and the button is back.

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

This is because I have a res.redirect back to the page in my function (below).

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}`);
}

How do I get the button to POST data then have the card show a "thank you" or just have the button go away?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

  1. When you click on button - store identifier of customer in the cookie/localStorage
  2. When load the page - check if there is the cookie, if present - hide button
  3. Use Promises - addGuest should return Promise and in your buttonDisappear function resolve it:
addGuest(someArgs).then(() => {
   // save cookies
   // show card
});
about 4 years ago · Santiago Gelvez Relatório
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