***JAVASCRIPT***
I need JAVASCRIPT codes for this question. Also a little explanation and full screenshots of the codes.
mpg.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- title for web page -->
<title>Calculate MPG</title>
<!-- link is used for stylesheet -->
<link rel="stylesheet" href="mpg.css">
<!-- script is used for javascript -->
<script src="mpg.js"></script>
</head>
<body>
<main>
<h1>Calculate Miles Per Gallon</h1>
<!-- label for miles -->
<label for="txtMiles">Miles Driven:</label>
<!-- textbox for miles -->
<input type="text" id="txtMiles">
<!-- span to display error message -->
<span id="miles"></span><br>
<!-- label for gallons -->
<label for="txtGallons">Gallons of Gas Used:</label>
<!-- textbox for gallons -->
<input type="text" id="txtGallons">
<!-- span to display error message -->
<span id="gallons"></span><br>
<!-- lable for miles oer gallon -->
<label for="mpg">Miles Per Gallon</label>
<!-- textbox for mpg -->
<input type="text" id="txtMPG" disabled><br>
<label> </label>
<!-- button to calculate mpg -->
<input type="button" id="btnCalculate" value="Calculate MPG"><br>
<label> </label>
<!-- button to clear enteries -->
<input type="button" id="btnClear" value="Clear Entries"><br>
</main>
</body>
</html>
***********************
mpg.js :
//function to calculate MPG
function calculateMPG(miles, gallons) {
return (miles / gallons).toFixed(1);
};
//function to process enteries
var processInputs = function() {
//getting miles entered by user
var miles = document.getElementById("txtMiles").value;
//getting gallons entered by user
var gallons = document.getElementById("txtGallons").value;
var flag = true;//variable used to store boolean value
//checking value of miles
if (isNaN(miles) || miles <= 0) {
//if miles is non numeric or less than 0 then
//display error message on the span
document.getElementById("miles").innerHTML="Miles must be numeric and greater than zero";
flag = false;//set flag to flase
}
//checking value gallons
if (isNaN(gallons) || gallons <= 0) {
//if gallons is non numeric or less than 0 then
//display error message on the span
document.getElementById("gallons").innerHTML="Gallons must be numeric and greater than zero";
flag = false;//set flag to false
}
//checking value of flag
if (flag) {
document.getElementById("miles").innerHTML="";//used to clear span
document.getElementById("gallons").innerHTML="";//used to clear span
//call function and display miles per gallon in the textbox
document.getElementById("txtMPG").value = calculateMPG(miles, gallons);
}
};
//function to clear inputs
var clearInputs=function() {
document.getElementById("txtMiles").value = "";
document.getElementById("txtGallons").value = "";
document.getElementById("txtMPG").value = "";
document.getElementById("miles").innerHTML="*";//used to clear span
document.getElementById("gallons").innerHTML="*";//used to clear span
};
//call function on the load of the window
window.onload = function() {
document.getElementById("btnCalculate").onclick = processInputs;
document.getElementById("btnClear").onclick = clearInputs;
document.getElementById("txtMiles").ondblclick = clearInputs;
document.getElementById("txtMiles").focus();//set focus to the miles textbox
};
===============================
Screen 1:mpg.html
Screen 2:mpg.html , screen when miles and gallons are not entered
Screen 3:mpg.html , screen when invalid gallons is entered
Screen 4:Screen showing miles per gallons
***JAVASCRIPT*** I need JAVASCRIPT codes for this question. Also a little explanation and full screenshots of...
In this exercise, you’ll upgrade a version of the MPG application so the error messages are displayed in span elements to the right of the text boxes. Open the HTML and JavaScript files in this folder: exercises_short\ch06\mpg\ Then, run the application and click the Calculate MPG button to see that an error message is displayed in an alert dialog box for each of the two input fields. 2. In the HTML file, add a span element after the input element...
create an application in VISUAL BASIC that calculates a cars gas mileage. The formula for calculating the miles that a car can travel per gallon of gas is MPG = Miles/Gallon In the formula MPG is miles-per-gallon, miles is the number of miles that can be driven on a full tank of gas, and gallons is the number of gallons that the tank holds. The applications form should have TextBox controls that let the user enter the number of gallons...
NEED HELP DIRECTIONS: Notice that there is one input area and two buttons There is a place in the HTML reserved for < li > elements under the heading “Shopping List” Write a javascript program that will cause whatever the user inputs to be placed in a newly -created < li > tag and the tag placed inside the < ul > element whenever the user clicks the button Your program must not create any < li > tag is...
NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...
I have some code for HTML/Javascript but I need to change it up a bit. Heres the assignment and what I have. The part in the bold is what I need help with. I need a button called new timer for when it reaches zero... Thank you. Assignment For this assignment, you will write a timer application in HTML and JavaScript. Your HTML document should contain the following elements/features: HTML tags: An <input> tag labeled "Timer Duration" with the initial...
HTML------------------------------------------------------CSS---------------------------------------------------WEB230 - JavaScript 1 Assignment 7 - FormsSome of these tasks would be better done in HTML or CSS but do them in JavaScript to practice whatwe have learned.1. Select the form element and save it in a variable. From here we can access all of the form fields.2. When the page loads do the following:add the password value "monkey"select the favourite city "New York"clear the textarea3. Add an event handler to the "name" field to change the background color...
given below are the project description and their Html and css files i need javascript according to the project and other files! WEB230 - JavaScript 1 Assignment 6b - Event Delegation Before starting, study the HTML and open it in a browser so that you understand the structure of the document. You will add functionality to perform several tasks in our shopping list app. Clicking the red "X" at the right of an item will delete that item. Clicking on...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...
New Perspectives on HTML5 and CSS3. Solve Chapter 13 Case Problem 3. mas_register.js "use strict"; /* New Perspectives on HTML5, CSS3, and JavaScript 6th Edition Tutorial 13 Case Problem 3 Filename: mas_register.js Author: Date: Function List ============= formTest() Performs a validation test on the selection of the conference session package and the conference discount number calcCart() Calculates the cost of the registration and saves data in session storage writeSessionValues() Writes data values from session storage in to the registration...
For milestone #1, we will start the CARIT site with three static HTML pages and a CSS file. Create a dedicated folder for this project. This folder should contain all related files in this project. The future milestones are cumulative and built directly on top of your prior work. Function/content requirements: A home page named “index.html”, which include these contents at least: Description of the center. You may reference the example sites. Latest news: use list tags; make up some...