Created
June 21, 2019 15:06
-
-
Save be-mohand/0f49ede39775b03a37073fc15fa61dd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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