Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  40] [ 3]  / answers: 1 / hits: 44261  / 11 Years ago, tue, june 18, 2013, 12:00:00

This is my code:


var $from = $("#fromDate").datepicker('getDate');
var $to = $("#toDate").datepicker('getDate');
if($from > $to)
alert("from date shouldn't greater than To date");

It is working if it is two dates in the same year. Otherwise, for example
fromDate='1/12/2012'(dd/mm/yyyy) toDate='18/6/2013'(dd/mm/yyyy), while you check the condition, it is not working. It throws an alert, which is given.


More From » jquery

 Answers
18

Auto limit your dates instead. In this example the second combo box won't allow you to pick a lower date than the one you pick on the first one.


$(document).ready(function() {

$("#txtFromDate").datepicker({

numberOfMonths: 2,

onSelect: function(selected) {
$("#txtToDate").datepicker("option", "minDate", selected)
}
});

$("#txtToDate").datepicker({

numberOfMonths: 2,

onSelect: function(selected) {
$("#txtFromDate").datepicker("option", "maxDate", selected)

}
});
});

Here is a working demo.


[#77565] Monday, June 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;