Link to home
Start Free TrialLog in
Avatar of shwelopo
shwelopo

asked on

date field

How do I prevent a date field mmddyy from accepting a past year.  right now, the ui (jsp) does not accept a past date if it is the current year, but if you put a date with a past year, it accepts.  Thanks.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Code?

Output?
Avatar of shwelopo
shwelopo

ASKER

Attached is the jsp
What is
history.forward();
doing for you?

Anyway. Your date picker is ancient. Also you are deep linking Matt's JS file - that is not nice.

You can get a much more refined one using jQuery UI

Is that an option?

Also most of the code is non-optimal. Have you considered rewriting it?
There is a LOT of inline script that does not belong there.
I did not write the original script.  I spent most of my time converting neat-3 and or cobol/mainframe programs to pc-based platform.  I was asked to fix this date issue as the person is no longer there.  the problem here is these people have customized everything from a while back to fit their customized programs.  If you can help me fix the date issue and modify the script to make it better, I'm all for it.  Jquery is an option.  Thank you.
Ok, I'll see what I can do
Please note experts are unpaid volunteers
much appreciated.
Wow. Very poor code.

For example

    checkDate = document.mainForm.first_Date.value
    checkDate = document.mainForm.reterm2_Date.value
    checkDate = document.mainForm.reterm3_Date.value
    checkDate = document.mainForm.reterm4_Date.value
    checkDate = document.mainForm.reterm5_Date.value
    checkDate = document.mainForm.reterm6_Date.value
    checkDate = document.mainForm.reterm7_Date.value
    checkDate = document.mainForm.reterm8_Date.value
    checkDate = document.mainForm.reterm9_Date.value

after all this only the last is tested.

but the function it is in is never called so unless there is an include I am missing, such as
<%@ include file="countryNumber.html" %>
 this code can be deleted

  function check_DateOrder(dateVal) {
    var inputDate = dateVal.value;
    inputYear = inputDate.substring(6,8);
    inputDay = inputDate.substring(3,5);
    inputMonth = inputDate.substring(0,2);
    var checkDate = "";
    checkDate = document.mainForm.first_Date.value
    checkDate = document.mainForm.reterm2_Date.value
    checkDate = document.mainForm.reterm3_Date.value
    checkDate = document.mainForm.reterm4_Date.value
    checkDate = document.mainForm.reterm5_Date.value
    checkDate = document.mainForm.reterm6_Date.value
    checkDate = document.mainForm.reterm7_Date.value
    checkDate = document.mainForm.reterm8_Date.value
    checkDate = document.mainForm.reterm9_Date.value
//    checkDate = document.mainForm.reterm10_Date.value
//    var today = new Date();
    todayMonth = checkDate.substring(0,2);
    todayDay = checkDate.substring(3,5);
    todayYear = checkDate.substring(6,8);
    var errorFlag = false;
    if (todayYear < inputYear && inputYear < 50) { errorFlag = true }
    if  ((todayMonth < inputMonth) && (todayYear == inputYear)) { errorFlag = true }
    if  ((todayDay < inputDay) && (todayMonth == inputMonth) && (todayYear == inputYear)) {
      errorFlag = true
    }
    if (errorFlag == true) { 
      alert('Date entered is future date - invalid entry.') 
      dateVal.focus();
      dateVal.select();
    }
  } 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial