Use javascript to get currency exchange rate

Comments

6 comments

  • Avatar
    Tony Ruth

    Hi Nando, any valid JS should work to the capabilities of the OS webkit. Are you getting any response back from your request to the server?

    0
    Comment actions Permalink
  • Avatar
    Nando Flores

    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.

    0
    Comment actions Permalink
  • Avatar
    Nando Flores

    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.

    0
    Comment actions Permalink
  • Avatar
    Tony Ruth

    Hey Nando, can you dump the response to a text field so you can see what you are getting back before you try and marry it to an option list key_value?

    0
    Comment actions Permalink
  • Avatar
    Nando Flores

    I really don't know how.
    I also have another question.
    Is there a way for me to get this value from the web only once per day, and if there is no internet, is there a way to use the last rate?

    0
    Comment actions Permalink
  • Avatar
    Tony Ruth

    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

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk