Skip to content

Instantly share code, notes, and snippets.

@paulmorriss
Last active August 29, 2015 13:59
Show Gist options
  • Save paulmorriss/10982078 to your computer and use it in GitHub Desktop.
Save paulmorriss/10982078 to your computer and use it in GitHub Desktop.
Set NetCommunity donation form fields according to values in URL - see http://manypies.paulmorriss.com/2013/06/netcommunity-donation-form-based-on-url.html
<!-- Javascript for parseQueryString -->
<script type="text/javascript" src="/NetCommunity/Document.Doc?id=10"></script>
<script type="text/javascript">
function replaceAmountRecipient()
{
var xyzPrefix = '';
xyzPrefix = Page_Validators[0].controltovalidate.substring(0,7);
//If it is a three digit prefix then we chop it down
if (xyzPrefix.slice(-1) != "_") {
xyzPrefix=xyzPrefix.substring(0,6);
}
var queryData = parseQueryString(location.search);
// Replace amount with that encoded in the URL: amount=99 say
// so long as there is not anything in there anyway
if ($('#'+xyzPrefix + 'txtAmount').val()==='') {
if (queryData.amount) {
$('#'+xyzPrefix + 'txtAmount').val(queryData.amount[0]);
}
}
// If free text field is hidden, (style=display:none) i.e. page has just been loaded from scratch then...
if ($('#'+xyzPrefix + 'trDesignationOther').length>0) {
if ($('#'+xyzPrefix + 'trDesignationOther').attr('style') !== '')
{
if (queryData.recipient) {
if (isNaN(queryData.recipient[0])) {
// Recipient contains text:
//Choose other from dropdown
$('#'+xyzPrefix + 'ddlDesignations').val('{0381473C-0F0D-4c0f-AD74-4BFAF6A4AD8D}');
//This used to be necessary to case the selected value to appear, but it does not seem to be
//and it makes the page jump so has been removed.
// document.getElementById(xyzPrefix + 'ddlDesignations').scrollIntoView();
// Set free text field and unhide it
$('#'+xyzPrefix + 'txtDesignation').val(queryData.recipient[0]);
$('#'+xyzPrefix + 'trDesignationOther').removeAttr('style');
}
else
{
if (queryData.recipient[0] !=='') {
if (queryData.recipient[0] !=='-1') {
// If the recipient is numeric then choose the value from the dropdown. The numbers used for the
// dropdown are probably page specific.
$('#'+xyzPrefix + 'ddlDesignations').val(queryData.recipient[0]);
}
} else
{
// If nothing is specified then the dropdown does not change
}
}
}
else { //No recipient, default to other on dropdown and prompting text in other field
//Choose other from dropdown
$('#'+xyzPrefix + 'ddlDesignations').val('{0381473C-0F0D-4c0f-AD74-4BFAF6A4AD8D}');
// Set free text field and unhide it by removing hidden style
$('#'+xyzPrefix + 'txtDesignation').attr('placeholder','Enter member or project name here');
$('#'+xyzPrefix + 'trDesignationOther').removeAttr('style');
}
}
}
}
function runit3(){
window.onload = replaceAmountRecipient;
}
runit3();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment