Click here to Skip to main content
15,846,211 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
Hi Friends,

I am having two drop down lists one is start date and second one is end date
in the drop down list i am having years.Now i want to validate that end date should always greater than start date.i.e when i selected an year 2000 in the start date and if i select year less than 2000 in the second end drop down it should show an validation message.

Please provide me any help

Updated 30-Oct-17 7:25am

i think this will help you[^]

Check the Operator and Type Property
Share this answer
Vani Kulkarni 26-Jun-12 0:32am    
Good answer 5!
Try this:
function DateCheck()
  var StartDate= document.getElementById('txtStartDate').value;
  var EndDate= document.getElementById('txtEndDate').value;
  var eDate = new Date(EndDate);
  var sDate = new Date(StartDate);
  if(StartDate!= '' && StartDate!= '' && sDate> eDate)
    alert("Please ensure that the End Date is greater than or equal to the Start Date.");
    return false;

Refer some similar answers:
end date greater than start date - jquery validation[^]
Validation of Date using JavaScript[^]
JavaScript - Date Validation - Check End Date is greater than Start Date[^]
start date and end date validation in javascript[^]

Here's solved answer on CP:
Start Date and End Date Validation[^]
Share this answer
function ValidateEndDate() {
       var startDate = $("txtfromdate").val();
       var endDate = $("txttodate").val();
       if (startDate != '' && endDate !='') {
           if (Date.parse(startDate) > Date.parse(endDate)) {
               alert("Start date should not be greater than end date");
       return false;
Share this answer
anurag19289 8-Nov-13 12:08pm    

You can call a javacript function in "onchage" of the 2nd dropdown.

First of all register both the dropdowns with hidden fields in the page load like
Page.RegisterHiddenField("hidden field name", dropdownid.ClientID);

Then in the javascript, get the value of both the dropdowns like

Then check appropriately as you want, like
if(value of 1st dropdwn < value of 2nd drop down), show a message like
Alert("Your message")

Happy Coding :)
Share this answer
priya0143 27-Jun-12 0:31am    
Thank you Mohammed Mitwalli,
I don't want alert boxes.I want a validation message right to the drop down list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900