Skip to content

Instantly share code, notes, and snippets.

@jordanmessina
Created February 18, 2013 18:27
Show Gist options
  • Save jordanmessina/4979494 to your computer and use it in GitHub Desktop.
Save jordanmessina/4979494 to your computer and use it in GitHub Desktop.
This is an example of how you can dynamically change which Forge product a single button will open the checkout for. This example is integrated with the "PayPal Buy Now" button.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>
<script src="https://www.forgesimple.com/javascript/boom-goes-the-checkout-v1.js" type="text/javascript"></script>
<link href="https://www.forgesimple.com/stylesheets/buttons.css" rel="stylesheet" type="text/css">
<script type='text/javascript'>
$(document).ready(function(){
$('#paypal-select').change(function(){
switch($('#paypal-select').val())
{
case "Paperback (v1.2.1)":
$('#forge-href').attr('href', 'https://www.forgesimple.com/products/36/buy/');
break;
case "Hardback (v1.1.1)":
$('#forge-href').attr('href', 'https://www.forgesimple.com/products/37/buy/');
break;
case "Paperback (v1.1.1)":
$('#forge-href').attr('href', 'https://www.forgesimple.com/products/38/buy/');
break
}
});
});
</script>
</head>
<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="9DCTLYVCFYBRS">
<input type="hidden" name="on0" value="Versions">
<input type="hidden" name="currency_code" value="USD">
<table>
<tbody><tr>
<td>
<select name="os0" id="paypal-select">
<option value="Paperback (v1.2.1)">
Paperback (v1.2.1) $15.00 USD
</option>
<option value="Hardback (v1.1.1)">
Hardback (v1.1.1) $22.00 USD
</option>
<option value="Paperback (v1.1.1)">
Paperback (v1.1.1) $12.00 USD
</option>
</select>
<div><b class="highlight">Free shipping</b>
in the continental U.S.</div>
</td>
<td>
<div>
<a id="forge-href" href="https://www.forgesimple.com/products/36/buy/" class="forge-button activate-forge-checkout" target="_blank">Buy Now</a>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/x-click-butcc.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
</div>
</td>
</tr>
</tbody></table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment