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

230
Views
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 answers
Answer question

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