wood burning stoves*
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


JavaRanch » Java Forums » Java » Servlets
Bookmark "Dates in forms" Watch "Dates in forms" New topic
Author

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!
Brian
bcnice@mindspring.com
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Brain,
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.
http://javascript.internet.com/forms/val-date.html
regds
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!
Brian
bcnice@mindspring.com
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
GeeCON Prague 2014
 
subject: Dates in forms