Skip to content

Instantly share code, notes, and snippets.

@fiftyandfifty
Last active December 27, 2015 02:39
Show Gist options
  • Save fiftyandfifty/7253791 to your computer and use it in GitHub Desktop.
Save fiftyandfifty/7253791 to your computer and use it in GitHub Desktop.
Using the donately.loaded event: Setting the recurring option as default on a Donately Form Load
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery( window ).load(function() {
function receiveMessage(event){
try {var data = JSON.parse(event.data);}
catch (e) {var data = event.data;}
if(data.event == 'donately.loaded'){
jQuery('#donately-one-time-donation').prop('checked', false);
jQuery('#donately-recurring-donation').prop('checked', true);
}
}
if (window.addEventListener){
window.addEventListener('message', receiveMessage, false);
}
else if (window.attachEvent){
window.attachEvent('message', receiveMessage);
}
});
</script>
</head>
<body>
<script class="donatelyformjs"
src="http://www.dntly.com/assets/js/v1/form.js"
type="text/javascript"
async="async"
data-donately-id="1"
data-donately-ssl="1">
</script>
</body>
</html>
@fiftyandfifty
Copy link
Author

For this to work, you will need to host the form on a secure (SSL) page so that it doesn't insert an iFrame

You can also accomplish this and more by creating a completely custom form. There is a working starting point for that here:
https://gist.github.com/fiftyandfifty/1cff4b1a841bca08e35a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment