[thelist] Date contraint

Matt Warden mwarden at gmail.com
Tue Aug 3 14:12:56 CDT 2004


On Tue, 3 Aug 2004 12:35:09 -0400, VanBuskirk, Patricia
<pvanbuskirk at otc.fsu.edu> wrote:
> Does anyone know of a way in CDML (or perhaps Javascript) to limit a date to present day or future days only?  We have a form field for "disconnect date" on a web form, and we don't want people to be able to put in a date from the past.
> 
> Any ideas?
> 
> p.s. the info is going into a Filemaker Pro database

Yes, you can do this in javascript. Note, however, that since it's
javascript, someone can just disable it in their browser. You should
also be checking on the server-side if you have some sort of
server-side scripting available (which I assume you do, since you are
adding this to a databse).

You'd do something like this:

var oform = document.forms['formname'];

// current date
var rightnow = new Date();
var inputdate = new Date(oform.disyear, oform.dismonth, oform.disday);
// or you can use: var inputdate = new Date(oform.disdate);, but 
// then the input must be in the correct format for the script to
// work, or you'll have to use some sort of input mask

if (inputdate.getTime() > rightnow.getTime())
{
  // input represents a date which is in the future by at least
  // a day.
}
else
{
   // input represents a date which is equal to the current day
   // or in the past
}


Likely, you would wrap this in a function and call that function in
the onsubmit handler of the form, or (less reliable) as the onclick
handler of the submit button -- either way, you'd do something like
this:

onsubmit="return validate();"

and in the above code, you return true if the dates are valid, false otherwise.

Again, all someone has to do to get around this validation is turn off
javascript. It will only keep an honest man honest.



-- 

Matt Warden
Berry Neuroscience Lab
Department of Psychology
Miami University



This email proudly and graciously contributes to entropy.


More information about the thelist mailing list