Use javascript to get currency exchange rate
I want to use a javascript code that I found here:
https://gist.github.com/henrik/265014
That uses yahoo finance to return the currency conversion rate of a country that will be selected from a picklist.
The thing is that it seems that you can only use code that is supported by zerion and that is integrated in iform and not just any javascript code.
Can someone please tell me how can I use this or any other code to get the result that I want from yahoo finance?
Thanks.
-
No.
I was trying to use the format that is required in iform:
var genguid=function b(a), but their are 2 functions and I don't know id it will work.
Can you please help me figure this out, since I really need this.
If you could provide some sample code, I would be really grateful.
Thanks.
-
I tried something different and now I get NAN as result.
This is the code I am using:
genguid= function getRate(from, to) {
var script = document.createElement('script');
script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
document.body.appendChild(script);
}
function parseExchangeRate(data) {
var name = data.query.results.row.name;
var rate = parseFloat(data.query.results.row.rate, 10);
alert("Exchange rate " + name + " is " + rate);
}and in the picklist dynamic value, I am using my_element1=genguid(list_1,"USD"), where list_1 gives me the code for the country in key_value. Please tell me if I am doing something wrong.
Thanks.
-
I would suggest reading from the web and then writing the result back to a variable in the Form's page level javascript through the iForm Page API.
This allows you to keep the web communication on a server (rather than the client) and also gives you the offline and single day refresh needs you just asked for.
Hope that helps,
Tony
Please sign in to leave a comment.
Comments
6 comments