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 7563367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:38:58+00:00 2026-05-30T13:38:58+00:00

Im quite new at Javascript however I have been trying to create a currency

  • 0

Im quite new at Javascript however I have been trying to create a currency converter using html select which is working great, however when calling the function it seems to skip straight over the if statements straight onto the else { } statement

function convUSD()
{
    RATE_GBP = 0.632111252;
    RATE_EURO = 0.746435769;
    RATE_AUD = 0.92945441;

    if(document.selectBox.slBoxCurrency.selectedIndex == 0 &&  document.frmCurrencyC.radioUSD.checked)
    {
        window.alert("Sorry cant do USD to USD convertion! Please select another value.");
    }
    else if(document.selectBox.slBoxCurrency.selectedIndex == 0 &&  document.frmCurrencyC.radioGBP.checked)
    {
        inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
        outPutBox = inputBox * RATE_GBP;
        document.frmCurrencyC.textOutPutTotal.value = outPutBox;
    }
    else if(document.selectBox.slBoxCurrency.selectedIndex == 0 &&  document.frmCurrencyC.radioEURO.checked)
    {
        inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
        outPutBox = inputBox * RATE_EURO;
        document.frmCurrencyC.textOutPutTotal.value = outPutBox;
    }
    else if(document.selectBox.slBoxCurrency.selectedIndex == 0 &&  document.frmCurrencyC.radioAUD.checked)
    {
        inputBox = parseFloat(document.frmCurrencyC.textInputNum.value);
        outPutBox = inputBox * RATE_AUD;
        document.frmCurrencyC.textOutPutTotal.value = outPutBox;
    }
    else
    {
        window.alert("Whoops there was an error");
    }
}

The first If statement works fine however when I actually want to do for example USD to GBP it heads straight to the else statement.

If you guys spot any errors or just well anything it would be much appreciated.

  • 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-30T13:38:59+00:00Added an answer on May 30, 2026 at 1:38 pm

    You’ve got your logic mixed up:

    First you check to see which currency you are converting to by looking at which radio was selected:

    function calculateCC() {
        if (document.frmCurrencyC.radioUSD.checked) {
            convUSD();
        }
        // etc
    }
    

    Then I would expect you would look at the drop down list to see what currency you are converting from, but instead, you check the radios, enforcing that the drop down list selection matches the “to” currency:

    function convUSD() {
        ...
        if (document.selectBox.slBoxCurrency.selectedIndex == 0 &&
            document.frmCurrencyC.radioGBP.checked) {
            ...
        }
        // etc
    }
    

    Looking at your code, it seems that in your first function, you need to be checking for the “from” currency, not the “to” currency. So, in calculateCC(), look at the drop down list, instead of the radio buttons:

    function calculateCC() {
        if (document.selectBox.slBoxCurrency.selectedIndex == 0) {
            convUSD();
        }
        // etc
    }
    

    Working demo: http://jsfiddle.net/X8MyF/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to javascript but have undertaken a task to get better aquainted
Hi I am quite new to php but i have been following some tutorials
I'm quite new to php and have been reading Larry Ullman book to develop
I'm trying to improve my Javascript coding style and have been reading that it's
Dear experts, I am quite new to javascript and I often see coders use
Yo. I'm really quite new to this whole JavaScript business, not to mention AJAX,
Quite new to maven here so let me explain first what I am trying
Iam quite new to functions in SQL and I would like to create a
I am a quite new to web development and I am trying to do
We have created an invite function at our site in JavaScript using the Graph

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.