This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Servlets and the fly likes Dates in forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Dates in forms" Watch "Dates in forms" New topic

Dates in forms

Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
What do you think the best way to handle dates are in HTLM forms? Allowing the user to type in a date, giving them a recommended format and causing an error if they type it in wrong? Have the user select from a three separate list boxes the month, day, and year? Or some other way?
Thanks for the help!
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Personally I used mm-dd-yy format or other formats depending upon the need. I am not sure why I don't like those pull downs for each month,day,year selections. I just picked up a nice Java Script code snippet from this URL and used in one of my applications and it is great. Please take a look at it.
maha anna
[This message has been edited by maha anna (edited January 03, 2001).]
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Thank you maha anna, that looks very helpful. One question though, since that script allows for several different formats to be accepted, is there an easy way to convert the date string that comes in as a request parameter from the form, into a Date object?
For example, if someone types 1/3/01 and another person types 01.03.2001, both are valid. Do you have to use multiple SimpleDateFormat objects and parse through them or do you have some sort of method that parses the string and tries to figure the month, day, year and consruct a Date object from that?
Thanks for the help/suggestions!
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I don't think a general solution is possible. Not least because even a human can't reallyt know whether 01/03/01 means the 1st of March (European Style) or 3rd of January (US Style), and that's without even considering which century to use for the year. The best way I have seen of entering dates is to use one of the many pop-up JavaScript calendars.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Dates in forms
It's not a secret anymore!