Skip to content

Instantly share code, notes, and snippets.

@dalethedeveloper
Created October 16, 2012 20:38
Show Gist options
  • Save dalethedeveloper/3901835 to your computer and use it in GitHub Desktop.
Save dalethedeveloper/3901835 to your computer and use it in GitHub Desktop.
WuFoo Form Javascript Embed Hack - Scroll to top on submit / error
<!--
This is the standard Javascript embed code for a WuFoo form with an
added var (iamnotscrolling) that delays a scroll to the top of the form
on submit or error.
We are hijacking the resizeDone function which fires after the form is
modified (this may have unintended consequences).
-->
<div id="wufoo-q7q8234237">
Fill out my <a href="http://mywfacct.wufoo.com/forms/q7q8a7">online form</a>.
</div>
<script type="text/javascript">
// CUSTOM: used for a timeout dampener
var iamnotscrolling = true;
var q7q8234237;(function(d, t) {
var s = d.createElement(t), options = {
'userName':'mywfacct',
'formHash':'q7q8234237',
'autoResize':true,
'height':'2215',
'async':true,
'header':'show',
'ssl':true,
// CUSTOM: make sure autoResize:true is set and this funciton will be fired
'resizeDone':function(){
if( iamnotscrolling ) {
window.setTimeout("jQuery('html, body').animate({scrollTop: 0}, 500);iamnotscrolling=true;", 500);
iamnotscrolling = false;
}
}
// END CUSTOM
};
s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'wufoo.com/scripts/embed/form.js';
s.onload = s.onreadystatechange = function() {
var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;
try { q7q8234237 = new WufooForm();q7q8234237.initialize(options);q7q8234237.display(); } catch (e) {}};
var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);
})(document, 'script');</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment