Broll05

12-08-2010, 06:24 PM

I am having some trouble trying to fix my math equation to calculate the total rent by aquiring values from my form fields. Converting the date fields to days and finding the number of days via two date fields is mainly where I am having trouble. Also, I am trying to have a window pop up before submission but the onclick event does not seem to function properly. Any suggestions would be greatly appreciated. Thank you.

Below is the math equation I have come up with:

//calculate days from date field

function calcTotal(date1, date2) {

//assign variables

var equip = parseFloat(document.forms[0].equipment.value)

var pDate = parseFloat(document.forms[0].pickupDate.value)

var pHours = parseFloat(document.forms[0].pickupHours.value)

var pMinutes = parseFloat(document.forms[0].pickupMinutes.value)

var rDate = parseFloat(document.forms[0].returnDate.value)

var rHours = parseFloat(document.forms[0].returnHours.value)

var rMinutes = parseFloat(document.forms[0].returnMinutes.value)

// The number of milliseconds in one day

var ONE_DAY = 1000 * 60 * 60 * 24

// Convert both dates to milliseconds

var date1_ms = rDate.getTime()

var date2_ms = pDate.getTime()

// Calculate the difference in milliseconds

var difference_ms = Math.abs(date1_ms - date2_ms)

//calculate total cost and diplay in window.confirm() dialog box

var pTime = pHours + pMinutes;

var rTime = rHours + rMinutes;

var total = (((difference_ms/ONE_DAY) - 1) * 24) * equip + ((rTime + (24 - pTime)) * equip);

var OK = window.confirm(" The total rental cost is $" + total + "\n Click OK to accept, Cancel to decline");

if (OK) {return true}

else {return false}

}

Below is the body section of the form:

<input type = "submit" name = "submit" value = "Submit Reservation" onclick = "calcTotal()"/>

Below is the math equation I have come up with:

//calculate days from date field

function calcTotal(date1, date2) {

//assign variables

var equip = parseFloat(document.forms[0].equipment.value)

var pDate = parseFloat(document.forms[0].pickupDate.value)

var pHours = parseFloat(document.forms[0].pickupHours.value)

var pMinutes = parseFloat(document.forms[0].pickupMinutes.value)

var rDate = parseFloat(document.forms[0].returnDate.value)

var rHours = parseFloat(document.forms[0].returnHours.value)

var rMinutes = parseFloat(document.forms[0].returnMinutes.value)

// The number of milliseconds in one day

var ONE_DAY = 1000 * 60 * 60 * 24

// Convert both dates to milliseconds

var date1_ms = rDate.getTime()

var date2_ms = pDate.getTime()

// Calculate the difference in milliseconds

var difference_ms = Math.abs(date1_ms - date2_ms)

//calculate total cost and diplay in window.confirm() dialog box

var pTime = pHours + pMinutes;

var rTime = rHours + rMinutes;

var total = (((difference_ms/ONE_DAY) - 1) * 24) * equip + ((rTime + (24 - pTime)) * equip);

var OK = window.confirm(" The total rental cost is $" + total + "\n Click OK to accept, Cancel to decline");

if (OK) {return true}

else {return false}

}

Below is the body section of the form:

<input type = "submit" name = "submit" value = "Submit Reservation" onclick = "calcTotal()"/>