Date Validation - Disallow Past Dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dale

    Date Validation - Disallow Past Dates

    Hi Everyone,

    I've got a form that provides a pop-up calendar for users to select
    dates for requesting jobs to be completed. The calendar works great,
    but it unfortunately allows users to select dates earlier than today
    (which they should't be allowed to do). I've started coding some
    validation scripts, but I'm stuck now and my approach doesn't seem to be
    working.

    I've Googled all morning looking for an answer and couldn't find one and
    I searched the newsgroups as well. Below is my code:

    <html>
    <script language="JavaS cript" type="text/javascript">
    <!--


    var now = new Date(); // Create a new Date Object
    var day = now.getDay(); // day returns integer of 0-6 which will be
    stored in the variable day
    var month = now.getMonth(); // month returns integer of 0-11 which will
    be stored in the variable month
    var date = now.getDate(); // day returns integer of 1-31 which will be
    stored in the variable date
    var year = now.getYear();
    if (year < 2000) year += 1900

    var tom = new Date("December 9, 2003");
    var newday = tom.getDay();
    var newmonth = tom.getMonth();
    var newyear = tom.getYear();

    document.write( "Now is <b>" + now + "<br>");
    document.write( "Today is: <b>" + month+date+year + "<br>");
    document.write( "Today is: <b>" + month + "/" + date + "/" + year +
    "</b><br>");
    document.write( "Var date is <b>" + tom + "<br>");
    document.write( "Var day is <b> " + newday + "<br>");
    document.write( "Var month is <b> " + newmonth + "<br>");
    document.write( "Var year is <b> " + newyear + "<br>");
    -->
    </script>

    <form method="post" name="data" onSubmit="retur n isitToday()">
    <input type="text" name= "mydate">
    <input type="submit" value="Check">
    </form>

    </html>


    Thanks!

  • Matt Kruse

    #2
    Re: Date Validation - Disallow Past Dates

    "Dale" <Dale@somewhere .com> wrote:[color=blue]
    > I've got a form that provides a pop-up calendar for users to select
    > dates for requesting jobs to be completed. The calendar works great,
    > but it unfortunately allows users to select dates earlier than today
    > (which they should't be allowed to do).[/color]

    I've got a popup calendar which will allow you to disable past dates:


    And I've also get general date routines which will allow you to check and
    validate dates and such:


    Hope that helps!

    Matt


    Comment

    • Dale

      #3
      Re: Date Validation - Disallow Past Dates

      Matt Kruse wrote:

      [color=blue]
      > I've got a popup calendar which will allow you to disable past dates:
      > http://www.mattkruse.com/javascript/calendarpopup/
      >[/color]


      Thanks Matt! I sent you an email off-line.

      Dale

      Comment

      • Dr John Stockton

        #4
        Re: Date Validation - Disallow Past Dates

        JRS: In article <QVLBb.2807244$ Of.430587@news. easynews.com>, seen in
        news:comp.lang. javascript, Dale <Dale@somewhere .com> posted at Wed, 10
        Dec 2003 21:06:56 :-
        [color=blue]
        >I've got a form that provides a pop-up calendar for users to select
        >dates for requesting jobs to be completed. The calendar works great,
        >but it unfortunately allows users to select dates earlier than today
        >(which they should't be allowed to do). I've started coding some
        >validation scripts, but I'm stuck now and my approach doesn't seem to be
        >working.
        >
        >I've Googled all morning looking for an answer and couldn't find one and
        >I searched the newsgroups as well.[/color]

        Did you not find the FAQ of this newsgroup sufficiently helpful? If you
        did not, why not?

        [color=blue]
        >var now = new Date(); // Create a new Date Object[/color]
        [color=blue]
        >var tom = new Date("December 9, 2003");[/color]

        I assume that you wish to compare now with tom and that tom should be in
        the future from 0000h today local time. The necessary test is shown by

        if (tom < now.setHours(0, 0,0,0)) alert("twirly")


        Validation : <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

        Comment

        • Dale

          #5
          Re: Date Validation - Disallow Past Dates

          Dr John Stockton wrote:

          [color=blue]
          > Did you not find the FAQ of this newsgroup sufficiently helpful? If you
          > did not, why not?[/color]

          I missed seeing the FAQ in my search attempts.
          [color=blue]
          >
          > I assume that you wish to compare now with tom and that tom should be in
          > the future from 0000h today local time. The necessary test is shown by
          >
          > if (tom < now.setHours(0, 0,0,0)) alert("twirly")
          >
          >
          > Validation : <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.
          >[/color]

          Thanks!

          Comment

          Working...