2 years ago
#61715
JeremyJed
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.
javascript
callback
settimeout
0 Answers
Your Answer