I am having some difficulty in constructing a window.confirm() function that works with my code. So if the form data is valid, I need to use a window.confirm() dialog box to show the user's total cost based on the rental rate of equipment chosen and the reservation period. The user must accept the cost by pressing the confirm button, and if user cancels do not submit data. I have written this code but cannot figure out how to find the number of days from the 2 date fields and use that to calculate and display the total cost. Any help with this will be greatly appreciate. Thanks so much.

var reserveDate = new Date(yr,mm,dd);
var mydate = new Date();
mydate.setDate(mydate.getDate()+2); // Two CLEAR days ahead - NB mydate is HRS:MNS:SECS so same date is a problem
if (reserveDate < mydate) {
window.alert("Reservations need to be at least two clear days in advance.");
document.getElementById("dateIn").value = ""; // clear the field
setTimeout("document.getElementById('dateIn').focus()", 25); // and refocus on it
}

Form validation of the pattern if (document.forms[0].firstName.value=="") { is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

The trouble with requiring an age of 18+ is that some people may not answer truthfully. And what if the users enters "Mickey Mouse"? And do you really require or need people to specify their return time to +-30 mintes?

You are proposing to use mailto:. The trouble with using this method (mailto) to send form results is its unpredictability. The method it is highly dependent on the browser in use and the email client in use (some people have only Yahoo or Hotmail). In particular, your visitor must have Outlook or Outlook Express as the default client for this to work correctly. Even if your visitor is using Internet Explorer, but the default mail client is different (e.g. Eudora), your mailto form will not work. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully send a mail will prompt the user by a security dialog prior to sending - this can scare many users from continuing. Also, what about people with Javascript disabled? If you are going to use a form then use a server-side formmail script as the action - there are several good free ones out there.

I have to say that there are many infelicities with your code. As this is plainly a commercial application I would suggest that you pay a professional to do the job properly. It will cost you far more in lost sales if users have a poor experience with your site perceiving it as amateur, and abandon you in favour of a competitor for ever.

BTW, when posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.

"One of the secrets of life is that all that is really worth the doing is what we do for others." - Lewis Carroll

Broll05

12-06-2010, 06:02 PM

Thanks for your response as this definitely helps me out with calling and validating a date function. This is just for a project I am doing to learn certain steps on how to understand Javascript. I appreciate all your help but I am really curious on how to take the pick up date field and the return date field and find the number of days so I can calculate the total cost of the rental equipment. Also, I am confused on how to display the total cost in a window.confirm() dialog box. If you could use your expertise to help me with this part that would be fantastic. Thank you so much for all your help.

Philip M

12-06-2010, 06:38 PM

I am glad to hear that you do not intend this to be a real website. :)

Thanks that will definitely help. Thats all I need? How can I incorporate the math equation from my first post, and where about do I put this function in the body part of the code to get the correct total amount? I think that the mat equation is right, but I am just not sure how to incorporate that part into a function which displays the total. You have been such a great help and I can't thank you enough. Thank You.

The code I am trying to use for the math equation is as follows, but I'm not sure where to put it into the body so the window.confirm() dialog box pops up and displays the correct total amount. This is where the day part comes in and where I have been having some trouble.