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

149
Views
I need help getting a javascript function to execute in correct order

I am having trouble grasping how to make this bit of code execute in the correct order:

window.writeData=function() {
  console.log('this works.');
  push(ref(db), {
          First_Name: document.getElementById("firstname").value,
          Last_Name: document.getElementById("lastname").value,
          Street: document.getElementById("street").value,
          City: document.getElementById("city").value,
          State: document.getElementById("state").value,
          Zip: document.getElementById("zip").value,
      }

  );
  window.location.href = 'calendar.html';}

What's suppose to happen is when a button with onclick="writeData() is pressed the various values gets written to the database and then the calendar.html page is loaded. However, as it is right now no data is being pushed to the database. I'm assuming its because the window.location.href = 'calendar.html'; is being executed first.

How do I prevent this? I've been trying to figure out if callback() or setTimeout() is the way to go, but I can't get anything to work properly.

about 4 years ago · Juan Pablo Isaza
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!