Forum Moderators: open
Anyone know a way I can use Javascript to put a USD value below the AUD value on my site, below each product, using an exchange rate stored in a database or file (updated by myself daily)
I don't actually know Javascript language so I need a pretty detailed explanation (I have been told that Javascript could do this function though). Thanks.
USD2AUD = 1.1;
EUR2USD = 1.5;
etc.
Then you can use these variables in your page to do you currency conversion.
Javascript is probably not the best way to do currency conversion. The best way would be to subscribe to a rates feed (XML, for example) and use a server side solution to provide accurate and up to date currency conversions.
XE.com [xe.com] provides both free and paid for services that may help.
1) Create a file that has something like this in it:
exchRate = 1.3;
function getUSD(price) {
document.write(price * exchRate);
}
2) Load this script on every page as an external JavaScript
3) Where ever you want the USD price to be displayed, simply do:
<script type="text/javascript"> getUSD('5.90'); </script>
...where 5.90, in this case, would be the AUD price.
4) This way, you only need to update one file (the external JavaScript) with the new exchRate.