JavaScript getting submit button to submit data (to google sheet) and redirect to another page simultaneously

  Kiến thức lập trình

I have a form as part of an app script for google sheets that gathers user emails and stuff for an event.

The code works perfectly and dovetails with the javascript part of the html page. The issue is when the person hits “submit” the page stays there rather than saying “you did it” or whatever.

The data is sent and stored correctly but I’m hoping to make that submiut button, submit the data collected and, at the same time, direct a person to another page where they see “you did it” and then get them to do something else if they want.

Javascript is not my strong suit so this is probably very easy. Also, this is a snippet so I’m guessing this is the salient piece of code, however, perhaps the fact it connects with a sheet means this is not a javascript situation and/or not a traditional “submit” situation. Anyway…

 <script type="text/javascript">
        $(document).ready(function($) {
   
            s1 = $(document).find('.screen_home').html();
            var e0 = $(document).find('.screen_data'); 

            e0.html(s1);

            $(document).on('click', '.btn_menu', function(event) {
                event.preventDefault();

                var screen_name = $(this).attr('screen_name');


                $(document).find('.screen_name').html(screen_name);

                if (screen_name == "home") {
                    var s1 = $(document).find('.screen_home').html();
                    e0.html(s1);
                } else if (screen_name == "about") {
                    var s1 = $(document).find('.screen_about').html();
                    e0.html(s1);

                } else if (screen_name == "services") {
                    var s1 = $(document).find('.screen_services').html();
                    e0.html(s1);

                } else if (screen_name == "contact") {
                    var s1 = $(document).find('.screen_contact').html();
                    e0.html(s1);
                }

            });

            $(document).on('click', '.btn_send_contact', function(event) {
              
              event.preventDefault();

              var e1 = $(this).closest('.screen_data');


              var a1={
                user_name:e1.find('.user_name').val(),
                user_email:e1.find('.user_email').val(),
                user_Username:e1.find('.user_Username').val(),
                user_msg:e1.find('.user_msg').val(),
                user_dttm:moment().format("YYYY-MM-DD HH:MM:SS A"),
              };

              console.log(a1);


              google.script.run.withSuccessHandler(function(data)
              {
                 
                if(data.status == "success"){

                }
                
              }).AddNewContact(a1) 


            });
        });
    

I’m not sure how to get two things to happen. I can make the button to be a link but clicking it doesn’t move the page along.

New contributor

Danielh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT