Auto click submit button on page load

An easy one for anyone familiar with custom code :sweat_smile:

I am a total newb at custom coding in Webflow but have nevertheless made an attempt at an email verification system where the user after signing up with their email clicks a URL from their inbox to arrive at a confirmation page with a confirm button. This submit button Iā€™d prefer to have auto-clicked upon page load rather than having the visitor manually click the link in the email only to then also click the button on the page in order to get redirected. My custom code does something but not what I want as it upon loading the page redirects me to the webhook which is the Action rather than to the Redirect URL I specified in the formā€¦

Below is the custom code I used to auto-click the submit button:

document.getElementById(ā€œredirectā€).click();

Note: all the other custom code found on the page is unrelated to the auto click script but necessary for the submission and redirect of the visitor to a CMS page. I just want the button clicked upon loadā€¦ nothing more, nothing less. Really hope one of you geniuses are able to help!

Not sure if the code is ideal but it worked for me:

<?php if ($_REQUEST['autosubmit']) { ?>
<script>
(function ($) {
  
    $(document).ready(function(){
        $('form#form-id').submit();
    });
  
})(jQuery);
</script>
<? } ?>

@Horizons12 where should the code implemented?