,
, , , , :
function CarRentalTotals() {
alert('CarRentalTotals called !');
console.log('CarRentalTotals, called');
...
- . /console.log, :
...
alert('MilesDriven = ' + MilesDriven + ', TotalCharge = ' + TotalCharge);
console.log('MilesDriven = ' + MilesDriven + ', TotalCharge = ' + TotalCharge);
}
/
. -, document.getElementById, name. :
1) id,
City: <input type="text" name="city" id="city"><br>
2) getElementById getElementsByName
var city = document.getElementsByName('city')[0].value;
,
var MilesDriven = document.getElementById('MilesDriven').value;
MilesDriven = odometerend - odometerbegin;
var TotalCharge = document.getElementById('TotalCharge').value;
TotalCharge = days * 15 + MilesDriven * 0.12;
but these two elements are not defined in the HTML that you inserted here.
If you want to display these values in HTML elements, your code should look like this:
var MilesDrivenElt = document.getElementById('MilesDriven');
MilesDrivenElt.value = odometerend - odometerbegin;
var TotalChargeElt = document.getElementById('TotalCharge');
TotalChargeElt.value = days * 15 + MilesDrivenElt.value * 0.12;
FROM
Miles Driven: <input type="number" name="MilesDriven" id="MilesDriven"><br>
Total Charge: <input type="number" name="TotalCharge" id="TotalCharge"><br>
NB: These items do not have to be <input>s.
Last tip: debug your code along the way
You should use the web developer console and console.log('message').
By the way, you added the jQuery tag to your question, but jQuery doesn't seem to be used here. It's great to learn vanilla JavaScript / HTML, but jQuery will make your life easier.