Results 1 to 4 of 4

Thread: Help with modifing a script written by jscheuer1

  1. #1
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Help with modifing a script written by jscheuer1

    Hi

    Trust you are all well.

    My currency script no longer works as they changed the api on the site for the rates. I have an api with a key, but the base is set to EUR and I'm in ZAR

    Your original script was
    Code:
    <script>jQuery(function($){function commatize(num){num=Math.ceil(num).toString(10).split("").reverse();var n=num.length,i=-1,newnum=[];while(++i<n){!(i%3)&&i&&newnum.push(",");newnum.push(num[i])}return newnum.reverse().join("")}jQuery.fn.currencyrates=function(rates){var base=this.text().replace(/\D/g,"");this.append(['<span class="usd usdsprite ocurtextsprite">$ ',commatize(base*rates.USD),'</span><br><span class="gbp gbpsprite ocurtextsprite"> ',commatize(base*rates.GBP),'</span><span class="eur eurosprite ocurtextsprite"> ',commatize(base*rates.EUR)].join(""))};$.getJSON("http://api.fixer.io/latest?base=ZAR",function(data){$(".divborder.col-md-1 h3:has(span.zar)").each(function(i,z){$(z).currencyrates(data.rates)})})});</script>
    http://data.fixer.io/api/latest?acce...R,MXN&format=1

    which gives the following:

    success true
    timestamp 1528194609
    base "EUR"
    date "2018-06-05"
    rates
    USD 1.16973
    ZAR 14.830536
    GBP 0.873718
    EUR 1
    So is it possible to change the script to use EUR as the base and then work out the other currencies based on the ZAR price??

    Thanks in advance

    Simon
    Very Best Rgds, Simonf :cool:
    __________________________________
    My Site | E-Mail Me

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    509
    Thanks
    9
    Thanked 59 Times in 57 Posts

    Default

    Please read their documentation:

    Changing base currency
    Provided changing base currency is supported on your subscription plan, you can change the currency to which your output currency rates are relative to by appending the base parameter to your API request URL and setting it to the three-letter code of your preferred base currency.


    Example:

    Code:
    https://data.fixer.io/api/latest
        ? access_key = API_KEY
        & base = USD
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  3. #3
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Yes I can for USD10 pm lol

    it give
    error
    code 105
    type "https_access_restricted"
    info "Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."
    http://data.fixer.io/api/latest?acce...,EUR,&format=1
    Very Best Rgds, Simonf :cool:
    __________________________________
    My Site | E-Mail Me

  4. #4
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    HI Guys

    FYI

    I figured out the sums to get it working

    Code:
    <script>jQuery(function($){function commatize(num){num=Math.ceil(num).toString(10).split("").reverse();var n=num.length,i=-1,newnum=[];while(++i<n){!(i%3)&&i&&newnum.push(",");newnum.push(num[i])}return newnum.reverse().join("")}jQuery.fn.currencyrates=function(rates){var base=this.text().replace(/\D/g,"");this.append(['<span class="usd usdsprite ocurtextsprite">$ ',commatize(base/rates.ZAR*rates.USD),'</span><br><span class="gbp gbpsprite ocurtextsprite"> ',commatize(base/rates.ZAR*rates.GBP),'</span><span class="eur eurosprite ocurtextsprite"> ',commatize(base/rates.ZAR)].join(""))};$.getJSON("http://data.fixer.io/api/latest?access_key=55fd0ac90898af48dee7fee59d7c7de5&symbols=USD,ZAR,GBP,EUR&format=1",function(data){$(".divborder.col-md-1 h3:has(span.zar)").each(function(i,z){$(z).currencyrates(data.rates)})})});</script>
    to view live page see the site:
    http://www.silvertreeestates.co.za

    rgds, Simon
    Very Best Rgds, Simonf :cool:
    __________________________________
    My Site | E-Mail Me

Similar Threads

  1. Music written by a charlatan
    By molendijk in forum The lounge
    Replies: 14
    Last Post: 07-14-2012, 02:29 AM
  2. Replies: 2
    Last Post: 08-02-2009, 05:31 AM
  3. Non-database 'CMS' written in PHP
    By Spinethetic in forum PHP
    Replies: 9
    Last Post: 05-04-2008, 08:47 PM
  4. Modifing style of popit menu
    By maverick in forum JavaScript
    Replies: 1
    Last Post: 03-15-2006, 06:38 AM
  5. Replies: 2
    Last Post: 08-16-2005, 02:27 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •