Skip to content

Instantly share code, notes, and snippets.

@be-mohand
Created June 21, 2019 15:06
Show Gist options
  • Save be-mohand/0f49ede39775b03a37073fc15fa61dd2 to your computer and use it in GitHub Desktop.
Save be-mohand/0f49ede39775b03a37073fc15fa61dd2 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
// Calcul price dynamically
if($('#listingForm').length > 0) {
var foreignRates = $.get('https://api.exchangeratesapi.io/latest?base=USD');
var foreignExchangeFunction = function() {
var USD_price = $('#ListingPrice');
USD_priceVal = USD_price.val() ? USD_price.val() : 0;
// Here is the magic - just get the user currency and do the math
// Convert is EUR
EUR_priceVal = USD_priceVal * foreignRates.rates.EUR;
$('#ListingPrice').append(EUR_priceVal + ' EUR');
};
$('#listingForm').on('keyup', '#ListingPrice', function() {
foreignExchangeFunction();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment