Trying to get an if statement based on data from a form submission to work with a countdown. I’m not getting any errors but this obviously isn’t working, it never redirects after the countdown no matter if I select yes or no. I’ve used wiki urls because I haven’t set up the 2 actual calendar urls yet. I realize this may have been a completely incorrect way to even attempt this, but I’m not well versed in java at all. Any and all help is appreciated.
// Total seconds to wait
var seconds = 10;
function countdown() {
seconds = seconds - 1;
if (seconds < 0) {
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
for (item in event.data.data) {
if (event.data.data[item]["name"] == "would_you_like_to_schedule_a_device_demo_") {
if (event.data.data[item]["value"] == "Yes") {
window.location = "https://en.wikipedia.org/wiki/Apple";
}
if (event.data.data[item]["value"] == "No") {
window.location = "https://en.wikipedia.org/wiki/Banana";
}
}
}
}
});
} else {
// Update remaining seconds
document.getElementById("countdown").innerHTML = seconds;
// Count down using javascript
window.setTimeout("countdown()", 1000);
}
}
// Run countdown function
countdown();