Skip to content

Instantly share code, notes, and snippets.

@idrakimuhamad
Last active January 2, 2016 08:59
Show Gist options
  • Save idrakimuhamad/8279834 to your computer and use it in GitHub Desktop.
Save idrakimuhamad/8279834 to your computer and use it in GitHub Desktop.
Example of creating PayPal button dynamically and getting the amount from user input using their PayPal Button JS.
body {
background: #DADADA;
font-size : 16px;
}
#price {
background: #DADADA;
padding : .5em;
border: 2px solid rgba(0,0,0, .35);
margin-right: 1em;
}
.btn {
text-decoration: none;
background: #AAAAAA;
padding : .4em .5em;
color: rgba(0,0,0, .5);
border-radius: 3px;
}
<label for="price">
Price
$ <input type="text" id="price" placeholder="Price" />
</label>
<a href="#" class="btn">Place Order</a>
<script>
document.querySelector('.btn').onclick = function(e) {
var price = document.querySelector('#price').value;
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'http://dl.dropboxusercontent.com/u/19076481/paypal-button.min.js?merchant=C9TYVAV5JMJLU';
s.setAttribute('data-button','buynow');
s.setAttribute('data-name', 'Empolyment Express Services');
s.setAttribute('data-quantity', '1');
s.setAttribute('data-amount', price);
s.setAttribute('data-currency', 'USD');
s.setAttribute('data-shipping', '0');
s.setAttribute('data-tax', '12.3');
document.body.appendChild(s);
e.preventDefault();
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment