简体   繁体   中英

Open JS pop-up when Submit is clicked

I have a contact form on my web site included where visitors have to fill in their name, address and email and now I try to add a content locker (javascript) which shall appear once they click on the "submit" button. The "onclick" works but the site automatically moves forward to the "submit.php" site and closes the content locker in seconds. I also want to have the visitors data already saved in case they close the site without paying attention to the PopUp. Is this possible?

Regards

Have you tried delaying the submission?

<script type="text/javascript">
        $(document).ready(function() {
            $('#myform').submit(function(e) {
                e.preventDefault();

                setTimeout(function () {
                    form.submit();
                }, 3000); // in milliseconds
            });
        });
    </script>

have you considered using AJAX?

use JQuery to lock the data in the form and send all the data to your submit.php with

<script>
$("input").prop('disabled', true);
var data = $('form').serialize();
$.post('url', data, function(){
 // do something when done saving
});
</script>

Information given from this answer: Pass entire form as data in jQuery Ajax function

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