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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:01:22+00:00 2026-05-20T10:01:22+00:00

What is wrong with my JavaScript? <?xml version = 1.0 encoding =utf-8?> <!DOCTYPE html

  • 0

What is wrong with my JavaScript?

<?xml version = "1.0" encoding ="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

 ...

<body> 
   <p>
   <a href="http://nova.umuc.edu/~ct386a28/handson/index.html">Main Page</a>
</p>
<h1>GAS MILEAGE CALCULATOR</h1> 

<form action="" method="post">

<script type = "text/javascript">

 function mileageCalculator (beginMil, endMil, galCons, form)
 {

    var bM = parseFloat(beginMil);
    var eM = parseFloat(endMil);
    var gC = parseFloat(galCons);

    if((eM<0)||(bM<0)||(gC<0))
    {
        alert("ERROR: One or more input(s) is negative.");
        form.begMileage = " ";
        form.endMileage = " ";
        form.galConsumed = " ";   
    }

    else if ((eM == 0) || (gC == 0))
    {
        alert("ERROR: The end mileage and/or gallon input is zero.");
        form.begMileage = " ";
        form.endMileage = " ";
        form.galConsumed = " ";            
    }

    else if (eM < bM)
    {
        alert("ERROR: End mileage is less than begining mileage.");
        form.begMileage = " ";
        form.endMileage = " ";
        form.galConsumed = " ";
    }
    else 
    {                               
        form.mpg.value = ((bM - eM) / gC);  

    } 
 }

 </script>



    <div class = "center">              
        <h3>Enter beginning mileage:</h3>   
        <input type="text"  name ="begMileage" tabindex="1" />
        <br />
        <h3>Enter ending mileage:</h3>
        <input type="text" name ="endMileage" tabindex="2"  />
        <br />
        <h3>Enter gallons consumed:</h3>
        <input type="text" name ="galConsumed" tabindex="3" />
        <br />

        <h2>TOTAL MILES PER GALLON</h2>
        <input type="text" name ="mpg" tabindex="4" /> <br />

    </div>

    <p><br /></p>

    <p>         
     <br /><input type="submit" value="SUBMIT" onclick = "mileageCalculator"/> <input type="reset" value="CLEAR"/> <br />
    </p>

</form>

  • 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-20T10:01:22+00:00Added an answer on May 20, 2026 at 10:01 am

    You can’t just submit a form to a function. You will have to get the form field values using some DOM method and pass it into your function. And vice versa, you have to access the form field you want to output to and set the value.

    Even though this is a bit out of date, this follows your pattern nicely.

    http://www.javaworld.com/jw-06-1996/jw-06-javascript.html

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

Sidebar

Related Questions

I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
<xsl:stylesheet xmlns=http://www.w3.org/1999/xhtml version=1.0 xmlns:ms=urn:schemas-microsoft-com:xslt xmlns:infoRequest=ControlSkin3 xmlns:xsl=http://www.w3.org/1999/XSL/Transform exclude-result-prefixes=xmlns> <xsl:output omit-xml-declaration=yes method=xml encoding=utf-8 /> I've got
What did I do wrong? Here is an excerpt from my code: public void
I need to serve XHTML pages that include Javascript. My problem is that Firefox
I am new to HTML/Javascript, as well as coding in general so bear with
Whats wrong with the following c# code? Compiler reports this error: Inconsistent accessibility: parameter
Why is it wrong to use std::auto_ptr<> with standard containers?
If something goes wrong in a WCF REST call, such as the requested resource
What's wrong with Linq to SQL? Or - what about Linq to SQL would
I wrote the wrong thing in a commit message. How can I change the

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.