How to delay form submission on a Hubspot landing page

Hi,

I have a Hubspot Landing page with a Hubspot form, added with a builder. I need to add a few seconds of a delay before submission starts. I tried with JavaScript to do that, but my code in not working, addEventListener not working on a Form object, and returns null, even console.log prints that object.

<script type="text/javascript">
window.addEventListener('message', event => {
 let $myForm = document.querySelector("form");
 console.log($myForm);

 $myForm.addEventListener('submit', function(ev) {
 ev.preventDefault(); 
 setTimeout(function() {
 ev.target.submit(); 
 }, 20000); 
 });

});
</script>

Is there any way to fix this, or is there any better way to delay form submission in Hubspot Landing page?

Thanks in advance for your help!

Hi, @MarcoMi :waving_hand: Welcome to our community! Thanks for including your code example. I’d like to invite some of our community members to the conversation — hey @dsmarion @JBeatty @miljkovicmisa do you have any suggestions for @MarcoMi?

Thank you for taking a look! — Jaycee