0

So I would like my date picker to be validated, giving the user a error script if they pick a day that exceeds the current day. In other words, they must only be able to enter a date that has not yet occured. This is my script:

<script type="text/javascript">
            function checkForm(form)
            {
                var from_hour = document.getElementById('from_hour').value;
                var from_minute = document.getElementById('from_minute').value;
                var to_hour = document.getElementById('to_hour').value;
                var to_minute = document.getElementById('to_minute').value;
                if (from_hour > to_hour) {
                    alert('"From: H:"field cannot be larger than "To: H:" field');
                    return false;
                } else if (from_hour === to_hour) {
                    if (from_minute > to_minute) {
                        alert('"From: M:"field cannot be larger than "To: M:" field');
                        return false;
                    }


                }


            }

        </script>
        <legend>Time Log</legend>
        <form name="form" method="post" action="" onsubmit="return checkForm(this)"  >
            <table>

                <tr>
                    <td>Date:</td>
                    <td><input type="text" required name="date" id="date" /></td>
                <script>
                    $('#date').datepicker({dateFormat: "dd/mm/yy"});</script>


                </td>            </tr>

1 Answers1

0

If you want to disable past date as well as current date you can use following statement-

  $('#date').datepicker({minDate:1,dateFormat: "dd/mm/yy"});

Above statement will allow user to choose future date only

Domain
  • 11,562
  • 3
  • 23
  • 44