bruce said:
I have 3 dropdown boxes, Month, Day, Year.
As usual, a URL would have helped. In particular, it would have helped to
see whether this approach is feasible at all, since that depends on the
intended audience and on the kind of dates to be entered. Note that to the
majority of mankind, it is unnatural to enter a date in that order. But if
the audience is more or less limited to certain northern parts of the
American continent, you might adapt to the odd habits of its inhabitants.
People have addressed the issue of date input design, which is
understandable but mostly off-topic in this group. However, before
considering the programming challenge, you should really first make an
informed decision on the design problem. As a rule, there are two good ways
to read dates:
1) Free text input with some instructions on format. This means that you
need both client-side and server-side code to parse the data and to report
errors.
2) Graphic calendars where the user can just click on a date. These require
nontrivial programming and should be accompanied with some fallback
considerations.
So it isn't easy, and therefore you may consider easy ways of reading dates,
despite the reduced usability. If you label each field properly, the odds of
getting badly wrong data (e.g., July 4th when the user actually meant April
7th and thought he specified that) can probably be reduced to almost zero if
month _names_ (not numbers) are used.
When I change the month, I
want the contents of the Day dropdown box be adjusted to the correct
days in the new month. I would expect to be able to use an onChange
event on the Month dropdown box. I don't know how to reset and reload
the Day dropdown box.
There are several possible approaches. One of them is to dynamically modify
the select element by removing or adding options. As a simpler approach,
with some drawbacks (especially dependency on CSS) is to modify just the
appearance of the options, e.g. setting their display property (in styles)
to 'none' to remove an option from rendering. Yet another approach is to
generate the entire Day dropdown box dynamically after the month has been
selected. In each approach, you would need to consider what happens when the
user changes the month selection - perhaps after having selected day.
(Nasty, isn't it? What should happen if the user selected January 30, then
changed month to February.)
There's yet another tricky issue. How many days are there in February? It
depends on the year, and in this context, we would expect the user to select
year last...
So what I'd suggest is that you let the Day dropdown have options up to 31
and you check later, e.g. at form submission, that the date selected is
possible. For good usability, an error should be reported as early as
possible. This would require several event handlers and you would need to
decide what to do in error situations, in addition to reporting the error,
of course.