简体   繁体   中英

JavaScript alert after submitting a form

A form is made using HTML & CSS. After the user submits the form, he should get an alert box saying you will be redirected to the home page. Now, I want JavaScript to be added in that HTML, so as to get the alert box after clicking on the 'submit' button.

Instead of direct form submit, call a JS function and put confirmation with message of you want to ask user whether to submit the data or not. If you want to show any message and put redirection, then after success callback you can put that.

First whether u have created a button or input then add a function call and in head define a function , means if user hits the submit button then after alert box it should be redirected . So here is my some basic code hope so it will help u :

<!DOCTYPE html>
<html lang="en">

  <head>
    <script>
      function submitForm() {
        alert("This will Redirect YOU ");
        window.open("/here should be ur redirect link/");
      }
    </script>

  </head>
  <body>
    <input type="submit" onclick="submitForm()" />
  </body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM