AnsweredAssumed Answered

Form submission - scroll to top of page

Question asked by Moritz Trollmann on Feb 12, 2018
Latest reply on Feb 12, 2018 by Moritz Trollmann

Thanks to Sanford Whiteman I was able to add a thank you message after form submission.

The script works beautifully. What I would like to add is a scroll to the top of the page after submission but could not figure out how to do this.

 

I would appreciate it if someone could help me here.

 

Script used is:

 

<script src="//EnterYourReferenceHere.marketo.com/js/forms2/js/forms2.min.js"></script>

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<script>// <![CDATA[

MktoForms2.whenReady(function (form) {

    //Add an onSuccess handler

form.onSuccess(function(values, followUpUrl) {

     var email = form.vals().Email,

       firstName = form.vals().FirstName,

lastName = form.vals().LastName,

     html = "<h4 style='text-align: left;'>Thank you $firstName $lastName ($email) for your submission!<br/>Please check your email for a confirmation</h4>";

     html = html.replace("$firstName", firstName);

     html = html.replace("$email", email);

     html = html.replace("$lastName", lastName);

 

     // Get the form's jQuery element and hide it

     form.getFormElem().hide();

 

     // Return false to prevent the submission handler from taking the lead to the follow up url

     form.getFormElem().after(html);

     return false;

   });

});

// ]]></script>

Outcomes