I am trying to make a mock webpage that is designed to use HTML and Javascript to return the cost of a rental car for any given number of days. The HTML portion of the page works great, but when I press the button to calculate a total, it does not do anything. I've looked around the Internet in hopes of finding an answer for this issue, but no matter what I try it doesn't seem to want to work.
Here is the HTML portion of my code, which is working just fine
<form>
Name: <input type="text" name="name"><br>
Street Address: <input type="text" name="street">
City: <input type="text" name="city"><br>
State: <input type="text" name="state">
Zip Code: <input type="text" name="zip"><br>
Beginning Odometer Reading: <input type="text" name="odometerbegin">
Ending Odometer Reading: <input type="text" name="odometerend"><br>
Days of Use: <input type="number" name="days">
</form>
<button onclick="CarRentalTotals()">Click for Calculation</button>
Here is the JavaScript portion that I am trying to make the program print out when the "Click for Calculation" button is pressed:
<script>
function CarRentalTotals() {
var name = document.getElementById('name').value;
var street = document.getElementById('street').value;
var city = document.getElementById('city').value;
var state = document.getElementById('state').value;
var zip = document.getElementById('zip').value;
var odometerbegin = document.getElementById('odometerbegin').value;
var odometerend = document.getElementById('odometerend').value;
var days = document.getElementById('days').value;
var MilesDriven = document.getElementById('MilesDriven').value;
MilesDriven = odometerend - odometerbegin;
var TotalCharge = document.getElementById('TotalCharge').value;
TotalCharge = days * 15 + MilesDriven * 0.12;
}
</script>
Something tells me that this is an easy fix, but I am just a beginner and have been mulling through this code for quite a while with little success, so any help would be appreciated. Thank you for your time!
TotalChargeto the HTML.getElementByIdyou need to give your elements ID's rather than just names...