106 users online (0 members and 106 guests)  


  Results 1 to 3 of 3

Related

  1. Replies: 4
  2. Replies: 0
  1. #1
    carl22's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2007
    Posts
    1

    Converting script

    Hello. I am trying to write a curency changer script, this will convert between Euros and Dollars. I can't get parseFloat to work so I can't tell it the script will work? Does anyone have any idea where I am going wrong?

    Thank you.
    Code:
    <html>
    <head>
    <title></title>
    <script language="JavaScript" > 
    var currencyType;
    var amountEntered;
    var amountConvert;
    var ammountOfEuros;
    var numberOfDollars;
    var dollarRate;
    dollaRate = 1.27; 
    currencyType = window.prompt('Please enter the currency 0, Dollar 1, Euro',''); 
    currencyType = parseFloat(currencyType);
    while (currencyType >= 0 && currencyType < 2) 
    {
    currencyType = window.prompt('Please re-enter - currency should be 0 or 1', '');
    currencyType = parseFloat(currencyType);
    }
    amountEntered = window.prompt('Please enter the amount to be converted',''); 
    amountEntered = parseFloat(amountEntered);
    amountEntered = 
     
    amountOfEuros = amountOfDollars * dollarRate;
    amountOfDollars = parseFloat(amountOfDollars);
    document.write('total is ' + amountOfDollars + '<br>');
     
     
     
     
    </script>
    </head>
    <body>
    </body>
    </html>
    Last edited by HTML; 02-17-2007 at 09:33 AM.

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Converting script

    You need to change this line of code:

    Code:
    while (currencyType >= 0 && currencyType < 2)
    to this:

    Code:
    while (currencyType != 0 && currencyType != 1)
    I'm not the best javascript programmer in the world, but that will get you past the first problem anyway.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    739

    Re: Converting script

    Hi there carl22,

    here is an example of a currency converter ...
    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>



Tags for this Thread