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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:18:08+00:00 2026-06-11T08:18:08+00:00

i have a small problem. I’m learning Javascript and I decided to make a

  • 0

i have a small problem.

I’m learning Javascript and I decided to make a currency converter but, my page keeps refreshing after the data is being displayed.

Could anyone help me figure out why it’s acting this way? Thanks

website : http://nonlocalhost.uphero.com/index.html

<!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>
    <style type="text/css">
        * {font-size:13px;font-family:arial;background-color:black;color:white;padding:0;margin:0;}
        #wrapper {width:640px;margin:0px auto;}

        input {color:lime;width:150px;height:22px;}
        #money_to_convert, label:nth-child(3) {position:relative;top:100px;right:95px;}
        #my_currency {width:53px;height:22px;position:relative;top:100px;left:232px;}
        #converted_input, label:nth-child(5) {position:relative;top:134px;right:298px;}
        #convert_currency {width:53px;height:22px;position:relative;top:134px;left:175px;}
        #submit_button {width:52px;height:25px;position:relative;top:117px;right:230px;}
    </style>
    <script type="text/javascript">
        function output_value() {
            var my_input = Number(document.getElementsByName("user_input")[0].value);
            var my_output;
            var my_currency = document.convertions.currency_to_convert.value;
            var convert_to = document.convertions.convert_currency_to.value;


            if(my_currency == "USD"){
                if(convert_to == "CAD"){
                    my_output = my_input * 0.975;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "EUR"){
                    my_output = my_input * 0.775;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "GBP"){
                    my_output = my_input * 0.620;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "AUD"){
                    my_output = my_input * 0.956;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else{
                    alert("You can't convert the same currency.");
                }
            }else if(my_currency == "CAD"){
                if(convert_to == "USD"){
                    my_output = my_input * 1.025;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "EUR"){
                    my_output = my_input * 0.795;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "GBP"){
                    my_output = my_input *  0.636;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "AUD"){
                    my_output = my_input *  0.980;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else{
                    alert("You can't convert the same currency.");
                }
            }else if(my_currency == "EUR"){
                if(convert_to == "USD"){
                    my_output = my_input * 1.289;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "CAD"){
                    my_output = my_input * 1.257;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "GBP"){
                    my_output = my_input * 0.800;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "AUD"){
                    my_output = my_input * 1.233;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else{
                    alert("You can't convert the same currency.");
                }
            }else if(my_currency == "GBP"){
                if(convert_to == "USD"){
                    my_output = my_input * 1.610;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "EUR"){
                    my_output = my_input * 1.249;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "CAD"){
                    my_output = my_input * 1.571;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "AUD"){
                    my_output = my_input * 1.541;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else{
                    alert("You can't convert the same currency.");
                }
            }else if(my_currency == "AUD"){
                if(convert_to == "USD"){
                    my_output = my_input * 1.045; 
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "EUR"){
                    my_output = my_input * 0.810;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "GBP"){
                    my_output = my_input * 0.648;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else if(convert_to == "CAD"){
                    my_output = my_input * 1.019;
                    document.getElementsByName("convertion_output")[0].value = my_output;
                }else{
                    alert("You can't convert the same currency.");
                }
            }else{
                alert("Fatal Error, refresh the page.");
            }
        }
    </script>
</head>

<body>
    <div id="wrapper">
        <form name="convertions">
            <select name="currency_to_convert" id="my_currency">
                <option value="USD" selected>USD</option>
                <option value="CAD">CAD</option>
                <option value="EUR">EUR</option>
                <option value="GBP">GBP</option>
                <option value="AUD">AUD</option>
            </select>
            <select name="convert_currency_to" id="convert_currency">
                <option value="USD">USD</option>
                <option value="CAD" selected>CAD</option>
                <option value="EUR">EUR</option>
                <option value="GBP">GBP</option>
                <option value="AUD">AUD</option>
            </select>
            <label for="user_input">Amount:</label>
            <input type="text" name="user_input" id="money_to_convert" />
            <label for="convertion_output">Result:</label>
            <input type="text" name="convertion_output" id="converted_input" disabled="disabled" />
            <button onclick="output_value()" id="submit_button">Submit</button>
        </form>     
    </div>
</body>

</html>
  • 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-06-11T08:18:10+00:00Added an answer on June 11, 2026 at 8:18 am

    The default behavior of button is act like a submit button if it’s inside a form. If you add type=’button’, it stops acting like a submit button

    <button onclick="output_value()" type="button" id="submit_button">
    

    You can also just return false from the handler (like you could with <input type="submit">) to prevent the default behavior.

    <button onclick="output_value(); return false" id="submit_button">
    

    Not that you don’t really need a form here, since you’re not submitting it. Removing the form also fixes your problem.

    See How to prevent buttons from submitting forms

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

Sidebar

Related Questions

I have a small programming problem (php & javascript). On index.php page I'm printing
i have a small problem, i am creating a edit page in my asp.net
I am generating new xml file using perl script but I have small problem,
I would like to write to a text file, but I have small problem.
I have a small problem :) I was searching the web but didn't find
I have small problem with http 404 error, after click on 'allow' on facebook
I have a small problem with TFS. I am trying to zip files after
I have a small problem but cannot figure out why. On my django shell:
I have small problem. I'm trying to work on an XML file, but the
I have small problem and it might be silly somewhere, but still i have

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.