Skip to content

Instantly share code, notes, and snippets.

@shanaver
Created June 25, 2015 18:29
Show Gist options
  • Save shanaver/53a2cd277ed7d4fbefbe to your computer and use it in GitHub Desktop.
Save shanaver/53a2cd277ed7d4fbefbe to your computer and use it in GitHub Desktop.
Donately form.js Corporate Matching Example
<html>
<head>
<title>Corporate Matching</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{
$('#company').change(create_form)
})
function create_form()
{
var company = $('#company').val()
// EDIT THIS: USE YOUR DONATELY ID
var donately_id = document.createAttribute("data-donately-id")
donately_id.value = '198'
// EDIT THIS: USE YOUR STRIPE PUBLIC KEY
var stripe_key = document.createAttribute("data-stripe-publishable-key")
stripe_key.value = 'pk_test_3RHbTOppYXZtmgbpDJf9Pxe7'
var tracking_codes = document.createAttribute("data-donately-tracking-codes")
tracking_codes.value = company
var form = document.createElement('script')
form.type = 'text/javascript'
form.src = 'https://www.dntly.com/assets/js/v1/form.js'
form.async = false
form.setAttributeNode(donately_id)
// form.setAttributeNode(stripe_key)
form.setAttributeNode(tracking_codes)
// where do we put the form
var formhere = document.getElementById('formhere')
// remove any other forms
while (formhere.hasChildNodes()) {
formhere.removeChild(formhere.lastChild);
}
// add the form to the page
document.write.to = {filename: form.src};
formhere.appendChild(form);
}
</script>
</head>
<body>
<form>
<h2>Choose Your Company:</h2>
<select id="company">
<option></option>
<option>Apple</option>
<option>Google</option>
<option>Tesla</option>
</select>
<hr/>
<div id="formhere" style="width:600px"></div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment