Click here to Skip to main content
15,886,797 members

Currency Web services using HTML5 and javascript

LakshmiPriyaece asked:

Open original thread
Hi,
Please guide me i have added "http://www.webservicex.net/currencyconvertor.asmx" this currency web services in my project.I dont kniow how to call this web services in my code,
XML
<!DOCTYPE html>
  <head>
    <title>Simple Currency Converter</title>
    <style type="text/css">
      
    <script type="text/javascript">


        var symbol = ['US Dollar', 'British Pound', 'Euro',
                  'Canadian Dollar', 'Japanese Yen', 'Chinese Yuan', 'India', 'Singapore'];


        var rates = [ // [symbol][USD, GBP, Euro, c$, Yen, Yuan, India, Singapore]
                   [1, 0.64, 0.74, 1.00, 93.83, 6.23, 53.04, 1.24],
                   [1.57, 1, 1.15, 1.56, 146.82, 9.76, 83.03, 1.94],
                   [1.36, 0.87, 1, 1.35, 127.39, 8.46, 72.01, 1.68],
                   [1.00, 0.64, 0.74, 1, 94.12, 6.25, 53.20, 1.24],
                   [0.01, 0.01, 0.01, 0.01, 1, 0.07, 0.57, 0.01],
                   [0.16, 0.10, 0.12, 0.16, 15.06, 1, 8.51, 0.20],
                   [0.02, 0.01, 0.01, 0.02, 1.74, 0.12, 1, 0.02],
                   [0.81, 0.51, 0.60, 0.81, 75.01, 5.03, 43.33, 1]
                ];

        function $(x) { return document.getElementById(x); };
        function $$(x) { return parseInt($(x).value, 10); };

        window.onload = function () {
            for (var i = 0; i < symbol.length; i++) {
                $('cHave').options[i] = new Option(symbol[i], i);
                $('cWant').options[i] = new Option(symbol[i], i);
            }
            $('amount').onfocus = function () { this.value = '' };
            $('amount').onblur = calculate;
            $('cHave').onchange = calculate;
            $('cWant').onchange = calculate;
        };

        function calculate() {

            var a = Math.abs($$('amount') || 0); $('amount').value = a;
            var b = $$('cHave'), c = $$('cWant'), o = $('output');
            if (a <= 0 || b >= rates.length || c >= rates[b].length) o.innerHTML = '';
            else o.innerHTML = (a * rates[b][c]).toFixed(2) + ' ' + symbol[c];
            return false; // force no submit
        };
    </script>
  </head>
  <body>
    <h1>Simple Currency Converter</h1>
    <hr/>
    <div class="table" style="border:10px">
      <form onsubmit="return calculate();" style="width: 341px">
        <span class="style1">Amount (whole units)</span><input id="amount" value="0"/><br/>
        <span>Convert</span><select id="cHave"></select><br/>
        <span>Into</span><select id="cWant"></select><br/>
        <span>Result</span><label id="output" /></div>

      </form>
    </div>
  </body>
</html>


This is my code please guide me where i have to add this webservices for currency conversion.

Thanks,
P.LakshmiPriya
Tags: Javascript, HTML5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900