How do I show success message after submit and route to a url

how can I combine your script

this script

 <script>
    const form = document.querySelector('form');

    form.addEventListener('submit', function(event) {
     event.preventDefault();

     if (form.checkValidity() === false) {
       alert("failed");
       form.classList.add('was-validated');
     } else {
       alert("sucess");
       location.replace("https://www.google.com/");
     }
    }, false);
  </script>

and the scripts that call the user entry