View Full Version : Hide Submit on Date Select in Past

06-23-2012, 07:05 PM
Hey guys I need some assistance in developing a code that will hide the submit button of a form if a date in the past is selected. The variable for the date box is firstleveldate and the date appears in a MM-DD-YYYY format.


06-23-2012, 11:00 PM
Load the form with the submit button disabled, then place an onBlur event in the firstleveldate field that checks the date value. If it's before the current date, do nothing; if it's AFTER the current date (or is the current date?), then document.forms["formName"].submitButtonName.disabled = false;

06-23-2012, 11:57 PM
you can use this:
function TestDate(Input, CurDateValid){
var seg=Input.split('-');
var Dato=new Date(seg[2],seg[0]-1,seg[1]);
var Now=new Date();
var NowReset=new Date(Now.getFullYear(),Now.getMonth(),Now.getDate());
return ((CurDateValid?NowReset:Now)<=Dato);
to test if the date is valid.

If today is a valid date then

if (TestDate(firstleveldate,1)){
--show/enable button--
--hide/disable button--

if not:
if (TestDate(firstleveldate,0)){ // or: if (TestDate(firstleveldate)){
--show/enable button--
--hide/disable button--