Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:41:52+00:00 2026-05-28T07:41:52+00:00

I’m in the process of creating a small currency conversion script using the money.js

  • 0

I’m in the process of creating a small currency conversion script using the money.js library and have run into a problem with the .append(); part. Here is what I have so far:

<script type="text/javascript">
$(document).ready(function () {

    function pfxCurrencyConverter() {
        //get the users options from the form and store in variables
        var pfxFromCurrency = $('#pfx-from-currency').val();
        var pfxToCurrency = $('#pfx-to-currency').val();
        //set base options
        fx.base = pfxFromCurrency
        fx.settings = {
            from: pfxFromCurrency
        };
        //  get the amount input by the user
        var inputAmount = $('#pfx-input-amount').val();

        // Load exchange rates data via the cross-domain/AJAX proxy:
        $.getJSON('http://openexchangerates.org/latest.json', function (data) {
            // Check money.js has finished loading
            if (typeof fx !== "undefined" && fx.rates) {
                fx.rates = data.rates;
                fx.base = data.base;
            } else {
                // If not, apply to fxSetup global:
                var fxSetup = {
                    rates: data.rates,
                    base: data.base
                }
            }
            var convertedValue = fx.convert(inputAmount, {to: pfxToCurrency});

            $("#currencies").append("<li>New Value" + convertedValue + "</li>");
        });
    } //end pfxCurrencyConverter
    $(document).ready(function () {
        pfxCurrencyConverter();
    });
</script> 

</head>
<!-- output form for user to populate -->

<!-- Output the front end form, include external stylesheet and define customisable css -->

</head>
<!-- output form for user to populate -->
<body>
<form method="get" onsubmit="return pfxCurrencyConverter();">
Amount: <input type='text' id='pfx-input-amount' /><br />
From: <select id='pfx-from-currency'>
    <option>Please Choose</option>
    <option>GBP</option>
</select><br />
To: <select id='pfx-to-currency'>
    <option>Please Choose</option>
    <option>USD</option>
</select><br />
<input type='submit' value='Convert' />
</form>
<ul id="currencies"></ul>
</body>
</html>

I have also this in the html right after the submit button, it works fine with just a string but stops working once I add + convertedValue

<script>document.write("New Value" + convertedValue);</script>

Any help is greatly apprecited

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:41:52+00:00Added an answer on May 28, 2026 at 7:41 am

    The problem was that the .append() was being called before the value was returned from getJson(). Placing the .append() inside the .getJson() solved the problem. This works:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title></title>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
            <script src="http://josscrowcroft.github.com/money.js/money.js"></script>
            <script type="text/javascript">
    
                function ConvertMoney(to, from, amt) {
                    // Load exchange rates data via the cross-domain/AJAX proxy:
                    $.getJSON('http://openexchangerates.org/latest.json',
                            function (data) {
                                // Check money.js has finished loading:
                                if (typeof fx !== "undefined" && fx.rates) {
                                    fx.rates = data.rates;
                                    fx.base = data.base;
                                } else {
                                    // If not, apply to fxSetup global:
                                    var fxSetup = {
                                        rates: data.rates,
                                        base: data.base
                                    };
                                }
    
                                var result = "<li>" + fx.convert(amt, { from: from, to: to }) + "</li>";
                                $("#result").append(result);
                            });
                }
    
                $("#convert").live("click", function () {
                    var from = $("#pfx-from-currency").val();
                    var to = $("#pfx-to-currency").val();
                    var amt = $("#pfx-input-amount").val();
    
                    ConvertMoney(to, from, amt);
                });
    
    $(document).keypress(function(e) {
        if(e.keyCode == 13) {
              var from = $("#pfx-from-currency").val();
                    var to = $("#pfx-to-currency").val();
                    var amt = $("#pfx-input-amount").val();
    
                    ConvertMoney(to, from, amt);
        }
    });
    
            </script>
        </head>
        <body>
        Amount:
        <input type='text' id='pfx-input-amount' /><br />
        From:
        <select id='pfx-from-currency'>
            <option>Please Choose</option>
            <option>GBP</option>
        </select><br />
        To:
        <select id='pfx-to-currency'>
            <option>Please Choose</option>
            <option>USD</option>
        </select><br />
        <input type='button' id="convert" value='Convert' />
        <ul id="result">
        </ul>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.