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

  • Home
  • SEARCH
  • 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 6659137
In Process

The Archive Base Latest Questions

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

I’m working on an assignment in my beginner Javascript class that involves an element

  • 0

I’m working on an assignment in my beginner Javascript class that involves an element document.getElementById on the first line below the var total. There is an error of missing “;” but the semicolon is there. So I know that it must be something else. Here is the code. Any suggestions?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Price Calculator</title>
<script type="text/javascript">
function fixOrder(){
const TAX = 0.975;
var numPrice = parseFloat(document.getElementById("cost").value);


var subtotal = numPrice * TAX;
var total = subtotal + tax;
document.getElementById("cost").value = "$" cost.ToFixed(2);
document.getElementById("tax").value ="$" tax.ToFixed(2);
document.getElementById("total").value ="$" total.ToFixed(2);
}

function placeOrder(){
if (document.getElementById("cost") == ""
isNaN(document.getElementById("cost")
alert("Sorry,you must enter a numeric value to place order")
if (document.getElementById("tax") == ""
isNaN(document.getElementById("tax")
alert("Sorry, you must enter a numeric value to place the order");
}
</script>

</head>

<body bgcolor="#00f3F1">
<frame align="left">
<legend>
<h1 align="center">Price Calculator</h1>
</legend>
<form name="purchases" action="donut.php"  method="POST">

Price:<p> <input type="text" id="cost" name="cost" value="" onchange="fixOrder">
</p>
Tax:<p>  <input type="text" id="tax" name="tax" value="" onchange="fixOrder">
</p>
Total:<p> <input type="text" id="total" name="total" value="" >
</p>
</form>
</frame>



<div id="cost" name="cost" value="" onchange="placeOrder();"></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-05-26T01:59:48+00:00Added an answer on May 26, 2026 at 1:59 am

    As has already been pointed out by the numerous other answers, there are a multitude of problems with your code. This answer is intended to address all of the mistakes and shortcomings.

    I’ll go from the top of the posted code. Firstly, you may have simply not pasted it into the question, but you’re missing a DOCTYPE declaration at the top of the file. All HTML documents should begin with a DOCTYPE, for example:

    <!DOCTYPE html>

    Into the JavaScript, the const keyword, while valid, is not supported by a lot of older browsers and is definitely best avoided. Replace it with var, it will make no difference.

    To concatenate strings in JavaScript you use the + operator:

    document.getElementById("cost").value = "$" + cost.toFixed(2);

    Also notice that I’ve changed ToFixed to toFixed. Another problem with the above line is the variable cost, which you’ve not defined. You may have meant numPrice, but I’m not entirely sure!

    On the next line, you’re using tax instead of TAX. Variable names in JavaScript are case-sensitive, so tax is also undefined.

    Your if statement conditions are wrong. I’m assuming you meant this:

    if(document.getElementById("cost").value == "" || isNaN(document.getElementById("cost").value)
    

    There’s a few changes to that line. Firstly, you were comparing a DOM element itself (getElementById returns a DOM element), rather than the value of it. Secondly, you were missing the closing parentheses, and finally, you needed some operator between the two conditions. I think you were after the “or” operator, ||. There’s a similar issue with your second if statement.

    You’re missing a semi-colon off the end of your first alert line. While that’s still valid, it’s definitely good practice to always include the semi-colon.

    Back into the HTML, you’re trying to call the fixOrder JS function, but you’ve missed the parentheses:

    <input type="text" id="cost" name="cost" value="" onchange="fixOrder()">
    

    To be really picky, you shouldn’t really use inline event handlers, but I won’t go into that here.

    I’m not sure why you’re using a frame element the way you are, but I have a feeling it would be better replaced by a div, or simply nothing at all (again, I may not have the full picture if you haven’t posted the full code).

    On your body tag you’re using the bgcolor attribute. That should definitely be replaced by CSS. You can use the background-color property.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string

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.