Donation form: Automatically select designation based on the web address

[NEW: Updated to support the ‘Allow other designation’ option on donation forms]

Just a quick one here. Quite often users want to link to a NetCommunity donation form from another page or site and specify where the donation should go. This may be from a campaign page or fundraising email etc. Rather than having to create multiple donation form parts you can have the one with all your designations on it and then use the below snippet to specify the designation defaulted in the form.

Put the below in an unformatted text part somewhere on the donation page. You can then link to the page using https://[mysite]/donate?designation=[whatever] i.e. https://[mysite]/donate?designation=Emergency%20Response

Note: You may need to change the  var otherOption=’Please direct my gift to’ to your label for designation other.

<script type="text/javascript">
var otherOption = 'Please direct my gift to';

function getParameterByName(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var b="[\\?&]"+a+"=([^&#]*)";var c=new RegExp(b);var d=c.exec(window.location.href);if(d===null){return""}else{return decodeURIComponent(d[1].replace(/\+/g," "))}}$(document).ready(function(){var a=getParameterByName("designation");if(a!==''){var b=$('select[id*=_ddlDesignations]');if(b&&b.length>0){var other=false;var opt=b.find('option:contains("'+a+'"):first');if(opt.length===0){opt=b.find('option:contains("'+otherOption+'"):first');other=true}if(opt.length>0){opt.attr('selected',true).parent().change();if(other){$('input[id*=_txtDesignation]').val(a)}}}else{}}});
</script>