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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:03:07+00:00 2026-05-26T01:03:07+00:00

Yesterday I submitted this problem, got terrific responses but my code still didn’t work.

  • 0

Yesterday I submitted this problem, got terrific responses but my code still didn’t work. I modified my code based on another student’s code that works, but my code still won’t calculate but it validates in javascript. Any suggestions. This homework is due TONIGHT!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4       /loose.dtd">
<html>
<head>
<title>Price Calculator</title>
<script type="text/javascript">
    function fixOrder() {
        const TAX = 0.975;
        var numPrice;
        var total;
        var tax;

        numPrice = parseFloat(document.getElementById("cost").value, 10);
        tax      = parseFloat(document.getElementById("tax").value, 10);
        total    = parseFloat(document.getElementById("total").value, 10);
        numPrice = numPrice * TAX;
        total    = numPrice;
        total    = document.getElementById("total").value = "$" + total.toFixed(2);

        if (isNaN(numPrice)) {
            alert("Sorry,you must enter a numeric value to place order");
            numPrice = 0;
        }
    }
</script>

</head>

<body bgcolor="#00f3F1">

    <h1 align="left">Price Calculator</h1>

    <form name="form" id="form">
       <p>Price: <input type="text" id="cost" name="cost" value="" onchange=
       "fixOrder" /></p>

       <p>Tax: &nbsp; <input type="text" id="tax" name="tax" value="" onchange=
       "fixOrder" /></p>

       <p>Total: <input type="text" id="total" name="total" value="" disabled=
       "disabled" /></p>
    </form>
</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-05-26T01:03:08+00:00Added an answer on May 26, 2026 at 1:03 am

    JS Fiddle

    Your onchange event is onchange="fixOrder" which is not really doing anything. If you change it to fixOrder() you will call the function fixOrder when the change event is fired.


    Furthermore:

    • I don’t think const is a reserved word in JavaScript. I don’t think JS has constants. You should change that line from const TAX to var TAX;
    • Unlike parseInt, which takes two arguments (string and base/radix), parseFloat only takes one argument (string), so you can remove the , 10 from it

    I imagine you want something like:

    function fixOrder() {
        var TAX = 0.0975;
        var numPrice;
        var total;
        var tax;
    
        numPrice = parseFloat(document.getElementById("cost").value);
        tax      = parseFloat(document.getElementById("tax").value);
        total    = parseFloat(document.getElementById("total").value);
    
        numPrice = numPrice + (tax || numPrice * TAX);
        total    = numPrice;
        var dec  = new Number((total+'').split('.')[1])  || 0;
        total    = document.getElementById("total").value =
                      "$" + Number(parseInt(total)
                          + '.'
                          + Math.round(
                              ( (dec+''.split('').reverse().join('') )/100 + '').split('').reverse().join('')
                            )).toFixed(2);
                            );
    
        if (isNaN(numPrice)) {
            alert("Sorry,you must enter a numeric value to place order");
            numPrice = 0;
        }
    }
    

    This will use the dollar amount of tax you enter, or if that doesn’t exist, it will use the constant rate that you have supplied at the beginning (this was changed from .975 to .0975).

    Also, notice the new calculation from total, we’re taking the decimal part of the number, dividing it by 100 to get to two decimal places, reversing it back so it’s in the proper order again, and then rounding it to the nearest 1 (cent).


    HTML Body:

      <h1 align="left">Price Calculator</h1>
    
      <form name="form" id="form">
         <p>Price: <input type="text" id="cost" name="cost" value="" onchange="fixOrder()" /></p>
    
         <p>Tax: &nbsp; <input type="text" id="tax" name="tax" value="" onchange="fixOrder()" /></p>
    
         <p>Total: <input type="text" id="total" name="total" value="" disabled="disabled" /></p>
      </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I asked this post , but I am still having problems when I
Yesterday, I asked this question and never really got an answer I was really
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
Yesterday, after about two years we re-deployed our application. Code hasn't changed, but the
Last week we submitted our app to apple. Yesterday we got response from them.
Yesterday I read some code of a colleague and came across this: class a_class
I was having trouble getting my mail php mail script to work yesterday but
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this
Yesterday I got a call from a Microsoft representative asking if we supply hosted
Yesterday I found this function: function clone(obj) { return typeof obj === 'undefined' ?

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.