Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Currency Converter

    I'm working on a stock exchange that has a foreign exchange section. How would I code a currency converter with fixed exchange rates onto my site?

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,708
    Thanks
    0
    Thanked 237 Times in 232 Posts
    Hi there Dead Man's Eye,

    and a warm welcome to these forums.

    Here is a javascript example...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>currency convertor</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #container {
        width:320px;
        padding:5px 0 10px 10px;    
        border:3px double #000;
        font-family:verdana,arial,hevetica,sans-serif;
        font-size:16px;
        color:#000;
        background-color:#eee;
        margin:auto;
     }
    #container h1 {
        font-size:16px;
        text-align:center;
     }
    #container label {
        display:block;
        margin:5px 0;
     }
    #container input {
        width:100px;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
       var rate=0.761672633;
       var df=document.forms[0];
       document.getElementById('button').onclick=function() {
       rate=parseFloat(df[0].value);
    
    if((rate==0)||(rate=='')||(isNaN(rate))) {
       alert('please enter a conversion rate');
       return;
     }
    if((isNaN(df[1].value))||(isNaN(df[2].value))||(df[1].value=='')&&(df[2].value=='')) {
       alert('please enter a numerical value');
       df.reset();
    df[0].value=rate
       return;
     }
    if((df[1].value!='')&&(df[2].value!='')){
       alert('you can only do one calculation at a time');
       df.reset();
       return;
     }
    if(df[2].value=='') {
       df[3].value='\u20ac '+parseFloat(df[1].value*rate).toFixed(2)
       df[2].disabled=true;
       df[2].style.backgroundColor='#ccc';
    }
    if(df[1].value=='') {
       df[3].value='\u0024 '+parseFloat(df[2].value/rate).toFixed(2);
       df[1].disabled=true;
       df[1].style.backgroundColor='#ccc';
      }
     }
       document.getElementById('clear').onclick=function() {
       df[1].disabled=false;
       df[2].disabled=false;
       df[1].style.backgroundColor='#fff';
       df[2].style.backgroundColor='#fff';
       df.reset();
       if(rate!=0.761672633){
       df[0].value=rate;
      }
     }
    }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    
    <div id="container">
    <h1>change conversion rate to suit</h1>
    <label><input type="text" value="0.761672633"/> : dollar to euro rate</label>
    <label><input type="text" value=""/> : dollars to euros</label>
    <label><input type="text"value=""/> : euros to dollars</label>
    <label id="deg"><input type="text" readonly="readonly"/> : converted value</label>
    <input id="button" type="button" value="convert"/>
    <input id="clear" type="button" value="reset"/>
    </div>
    </form>
    
    </body>
    </html>
    coothead

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. My goal I to have one similar to the full converter located here with fixed rates. Would I just input the desired rate for each currency?

    A problem I came across is after switching it to convert the Cerulean Pound to the En (true name for ehat wee call the "yen") it won't convert.

    The code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>currency convertor</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #container {
        width:320px;
        padding:5px 0 10px 10px;    
        border:3px double #000;
        font-family:verdana,arial,hevetica,sans-serif;
        font-size:16px;
        color:#000;
        background-color:#eee;
        margin:auto;
     }
    #container h1 {
        font-size:16px;
        text-align:center;
     }
    #container label {
        display:block;
        margin:5px 0;
     }
    #container input {
        width:100px;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
       var rate=150.00;
       var df=document.forms[0];
       document.getElementById('button').onclick=function() {
       rate=parseFloat(df[0].value);
    
    if((rate==0)||(rate=='')||(isNaN(rate))) {
       alert('please enter a conversion rate');
       return;
     }
    if((isNaN(df[1].value))||(isNaN(df[2].value))||(df[1].value=='')&&(df[2].value=='')) {
       alert('please enter a numerical value');
       df.reset();
    df[0].value=rate
       return;
     }
    if((df[1].value!='')&&(df[2].value!='')){
       alert('you can only do one calculation at a time');
       df.reset();
       return;
     }
    if(df[2].value=='') {
       df[3].value='\u20ac '+parseFloat(df[1].value*rate).toFixed(2)
       df[2].disabled=true;
       df[2].style.backgroundColor='#ccc';
    }
    if(df[1].value=='') {
       df[3].value='\u0024 '+parseFloat(df[2].value/rate).toFixed(2);
       df[1].disabled=true;
       df[1].style.backgroundColor='#ccc';
      }
     }
       document.getElementById('clear').onclick=function() {
       df[1].disabled=false;
       df[2].disabled=false;
       df[1].style.backgroundColor='#fff';
       df[2].style.backgroundColor='#fff';
       df.reset();
       if(rate!=150.00){
       df[0].value=rate;
      }
     }
    }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    
    <div id="container">
    <h1>change conversion rate to suit</h1>
    <label><input type="text" value="150.00"/> : Pound to En rate</label>
    <label><input type="text" value=""/> : pounds to en</label>
    <label><input type="text"value=""/> : en to pound</label>
    <label id="deg"><input type="text" readonly="readonly"/> : converted value</label>
    <input id="button" type="button" value="convert"/>
    <input id="clear" type="button" value="reset"/>
    </div>
    </form>
    
    </body>
    </html>
    What's wrong?
    Last edited by Dead Man's Eye; 05-11-2007 at 07:48 PM.

  • #4
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    (blank, changed my mind)
    Last edited by Dead Man's Eye; 05-14-2007 at 04:03 PM.

  • #5
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why won't my code work? It should work so the person converting is able to select a rate from a list.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>currency convertor</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #container {
        width:320px;
        padding:5px 0 10px 10px;    
        border:3px double #000;
        font-family:verdana,arial,hevetica,sans-serif;
        font-size:16px;
        color:#000;
        background-color:#eee;
        margin:auto;
     }
    #container h1 {
        font-size:16px;
        text-align:center;
     }
    #container label {
        display:block;
        margin:5px 0;
     }
    #container input {
        width:100px;
     }
    </style>
    
    <script type="text/javascript">
    
    window.onload=function() {
       var rate=;
       var df=document.forms[0];
       document.getElementById('button').onclick=function() {
       rate=parseFloat(df[0].value);
    
    if((rate==0)||(rate=='')||(isNaN(rate))) {
       alert('please enter a conversion rate');
       return;
     }
    if((isNaN(df[1].value))||(isNaN(df[2].value))||(df[1].value=='')&&(df[2].value=='')) {
       alert('please enter a numerical value');
       df.reset();
    df[0].value=rate
       return;
     }
    if((df[1].value!='')&&(df[2].value!='')){
       alert('you can only do one calculation at a time');
       df.reset();
       return;
     }
    if(df[2].value=='0.00') {
       df[3].value='\u20ac '+parseFloat(df[1].value*rate).toFixed(2)
       df[2].disabled=true;
       df[2].style.backgroundColor='#ccc';
    }
    if(df[1].value=='') {
       df[3].value='\u0024 '+parseFloat(df[2].value/rate).toFixed(2);
       df[1].disabled=true;
       df[1].style.backgroundColor='#ccc';
      }
     }
       document.getElementById('clear').onclick=function() {
       df[1].disabled=false;
       df[2].disabled=false;
       df[1].style.backgroundColor='#fff';
       df[2].style.backgroundColor='#fff';
       df.reset();
       if(rate!=0.00){
       df[0].value=rate;
      }
     }
    }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    
    <div id="container">
    <h1>change conversion rate to suit</h1>
    <label><input type="text" value="0.00"/> : Rate</label>
    <label><input type="text" value=""/> : SCS to Foreign</label>
    <label><input type="text"value=""/> : Foreign to SCS</label>
    <label id="deg"><input type="text" readonly="readonly"/> : converted value</label>
    <input id="button" type="button" value="convert"/>
    <input id="clear" type="button" value="reset"/>
    </div>
    </form>
    
    </body>
    </html>
    Last edited by Dead Man's Eye; 05-14-2007 at 04:09 PM.

  • #6
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Better yet, Coothead, would you please tweak yours to have a list of rates instead of just one rate?
    Last edited by Dead Man's Eye; 05-17-2007 at 06:50 PM.


  •  

    Posting Permissions

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