JavaScript to Validate Date Input

Chris Kelleher

Administrator
Staff member
I'm SO close; here's the code so far:

<A HREF="http://www.fast4gl.com/ubb/uploads/validdate.js">validdate.js</A>

The only thing this doesn't do correctly is check the days in the month; as
you can see I've tried, but the else condition in the paragraph that starts
"validDate = 0" does what I've told it as opposed to what I want it to do
wink.gif

In exchange for providing this code for anybody's use who wants it, can
somebody help me to implement this one last piece of functionality
correctly.

Thanks in advance

George Jempty
 

Chris Kelleher

Administrator
Staff member
I'll try this out as soon as I can, but out of curiosity:

What difference does dividing by one make? I did some tests and determined
that JavaScript would properly deal with inMonth as an integer for the
purpose of indexing the daysPerMonth array, so that's not it, is it?

Thanks

George Jempty
 

Chris Kelleher

Administrator
Staff member
Yes, you were SO close. This should work:
if (inDate > daysPerMonth[inMonth / 1]) {
--
Steve Van Allen
TKI Consulting, Inc.
 

Chris Kelleher

Administrator
Staff member
Does anybody have a Javascript for validating that dates are in proper
Progress format that they would be willing to share

Thanks in advance

George Jempty
 

Chris Kelleher

Administrator
Staff member
I thought this was the Internet
wink.gif


Seriously, can you provide me with a specific URL? And bear in mind I'm
talking Progress formatted dates. I looked at a couple of scripts on
javascripts.com yesterday but they were terrible and beyond modification.

TIA

George Jempty
 

Chris Kelleher

Administrator
Staff member
Just to start a little controversy, I contend that this is not possible.

I don't mean to say that it's not possible to write a javascript function
that makes sure a date is acceptable to Progress, just that it's not
possible to validate the proper meaning of a date entered as a single
string using javascript.

All web design should be considered in an international context. It is
impossible to determine the true meaning of the string 04/03/2000. Is this
March 4th or April 3rd?

I always use three select objects for date input (Month spelled out, Day,
Year). Or you could certainly use three separate fields properly labelled.

If anyone has any better ideas I'd love to hear about them.

Tom Bergman
Tom_Bergman@SilverPlatter.com
 

Chris Kelleher

Administrator
Staff member
Actually I like your idea about creating a JS date object. But to be a
little more specific, I'm presenting a date for modification in a text
field. I'm pulling it straight from the database and it's in a format such
as: "01/23/45", which is the default per Progress documentation (without
having to fiddle with the -d parameter). So I want to send it right back to
the database after being modified by the end user, and I was wondering if
anybody had a canned script for validating a date is in the default Progress
format before submitting a form for processing.

Thanks for your patience

George Jempty
 

Chris Kelleher

Administrator
Staff member
That's what Tom Bergman's post was talking about. You can't tell. You
have to spit it out to the user in three input fields labeled month day
year.

If they type in 03/04/00 it could be march 4, or april 3. That date is valid
in both a mm/dd/yy and dd/mm/yy format. So you have to split it out into
three fields.
I've actually done that before for exactly this reason. Hope this helps.

Regards,

Sean Overby
Protech Systems Inc.
soverby@protech.com http://www.protech.com
"Stulti timent Fortunam, sapientes ferunt"
 

Chris Kelleher

Administrator
Staff member
I see your point; however I just need to crank out some quick and dirty
code, and probably won't be splitting it into three fields; maybe I'll just
advise the end user of the desired format. Then if they get it wrong, it's
their fault (like it's ever anybody else's
wink.gif


George Jempty
 

Chris Kelleher

Administrator
Staff member
It definitely is not possible. However, it's often sufficient to explain an
acceptable date format for a particular date field and enforce that. It's
also possible to take user preferences into account and apply an appropriate
date format based upon those preferences.

I personally find a UI that forces me to enter three separate pieces of
information for a date field to be tedious (although not as frustrating as a
long series of radio sets).

--Paul Galvin
ISSG
 

Chris Kelleher

Administrator
Staff member
I don't believe this is true. You can have your WS app
output the format of the date into the HTML as a JS var.
Then you simply invoke the appropriate validation routine
for the format you've output. You can wrap all JS date
routines up into a .JS file, then pass date value (that
the user entered) AND the format value (that your WS WO
has determined) to a JS Function that decides which date
validation JS Function to run.

Pretty straight forward, unless I'm missing something
(which is highly likely). :)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
R o b e r t J. M i r r o
rmirro@microserve.net http://www.microserve.net/~rmirro/

I am just a worthless liar
I am just an imbecile
I will only complicate you
Trust in me and fall as well...
- Tool
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Chris Kelleher

Administrator
Staff member
I just want to say thanks everybody! The solution I've decided on is to
advise the user I'm looking for month/date/year, and then use Mr.
Southwell's regular expression based script; finally, I'll use others' input
to add the necessary robustness to avoid February 30, "00/00/00" and so
forth.

Thanks again!

George Jempty
 
Top