Dynamically Change Donation Amounts Using Custom JavaScript
You can dynamically update donation amounts on your Raisely forms by using custom JavaScript and URL query parameters. This allows you to tailor donation buttons based on how a donor arrives at your site.
For technical background, check out our developer documentation: Modifying your campaign programmatically
Step 1: Add Custom JavaScript (for One-Off Donations Only)
- Go to Campaign > Settings > Apps & Integrations > Custom JavaScript
- Paste the following code:
function parseQuery(queryString) { var query = {}; var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&'); for (var i = 0; i < pairs.length; i++) { var pair = pairs[i].split('='); query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); } return query; } const myVars = parseQuery(window.location.search); window.setCampaignConfig('amounts', [ { "interval": "ONCE", "count": 1, "amounts": [ { "amount": myVars.button1 ? myVars.button1 * 100 : 3000, // always good to set a default, so 3000 refers to 30 dollars on the donation form "title": "One-time donation", "image": "" }, { "amount": myVars.button2 ? myVars.button2 * 100 : 5000, "title": "Support now", "image": "" }, { "amount": myVars.button3 ? myVars.button3 * 100 : 8000, "title": "Change lives today", "image": "" } ] } ]);
3. Click Save Changes
This script dynamically updates the ONCE donation frequency options based on the URL.
Step 2: Format Your Campaign URL
To activate the code, add query parameters like this:
https://your-campaign-url.com/?button1=25&button2=50&button3=75
Each parameter corresponds to a donation amount:
button1=25
→ $25 for button 1button2=50
→ $50 for button 2button3=75
→ $75 for button 3
If a parameter is missing, the default value from the script will be used.
How the Code Works
Key | Description |
---|---|
interval |
Donation frequency ( "ONCE" , "MONTH" , etc.) |
count |
Always set to 1 |
amount |
Value in cents (multiply dollar value by 100) |
title |
Text shown on the donation button (optional) |
image |
Optional image/icon (can leave as empty string, or the URL of the image from within your Raisely media library) |
Extending the Code (Optional: Add MONTH and YEAR)
To also support monthly and yearly intervals, expand your JavaScript like this:
window.setCampaignConfig('amounts', [ { "interval": "ONCE", "count": 1, "amounts": [ { "amount": myVars.button1 ? myVars.button1 * 100 : 3000, "title": "One-time donation", "image": "" }, { "amount": myVars.button2 ? myVars.button2 * 100 : 5000, "title": "Support now", "image": "" }, { "amount": myVars.button3 ? myVars.button3 * 100 : 8000, "title": "Change lives today", "image": "" } ] }, { "interval": "MONTH", "count": 1, "amounts": [ { "amount": myVars.button1 ? myVars.button1 * 100 : 2500, "title": "Monthly supporter", "image": "" }, { "amount": myVars.button2 ? myVars.button2 * 100 : 4000, "title": "Sustain our mission", "image": "" }, { "amount": myVars.button3 ? myVars.button3 * 100 : 6000, "title": "Help every month", "image": "" } ] }, { "interval": "YEAR", "count": 1, "amounts": [ { "amount": myVars.button1 ? myVars.button1 * 100 : 10000, "title": "Annual gift", "image": "" }, { "amount": myVars.button2 ? myVars.button2 * 100 : 20000, "title": "Support yearly", "image": "" }, { "amount": myVars.button3 ? myVars.button3 * 100 : 50000, "title": "Make a lasting impact", "image": "" } ] } ]);
Testing Tips
- Use a private/incognito browser to test fresh sessions
- Omit one of the button values to confirm fallback logic
- Confirm your form includes the ONCE, MONTH, and/or YEAR frequencies
Need Help?
If you'd like help testing this code or expanding it further, contact our support team — we're happy to assist!