Follow by Email

Sunday, April 13, 2014

Sample Code to validate from date and to date in JavaScript/jquery || checkin date and checkout date validation using JavaScript(js)

 Javascript :

Below is the code to validate fromdate and todate using javascript.

   function validateDate() {

            var fromdate, todate, date1, date2;
            var chkFrom = document.getElementById('date');
            var chkTo = document.getElementById('date2');

            fromdate = chkFrom.value;
            todate = chkTo.value;

            date1 = new Date(fromdate);
            date2 = new Date(todate);

            if (date2 <= date1) {
                alert("To date Should be greater than From date");

                return false;
            }
            return true
        }
    </script>

Web Page:

calling the above javascript function on button click

 <div>
 <button type="button" id="btnsubmit" class="btn"  onclick="return validateDate();"> Submit</button>
 </div>