Click here to Skip to main content
15,905,563 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

Thanks
Priya
Posted
Updated 30-Oct-17 6:25am

i think this will help you

http://www.w3schools.com/aspnet/control_comparevalidator.asp[^]

Check the Operator and Type Property
 
Share this answer
 
v2
Comments
Vani Kulkarni 26-Jun-12 0:32am    
Good answer 5!
Try this:
C#
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
 
C#
function ValidateEndDate() {
       var startDate = $("txtfromdate").val();
       var endDate = $("txttodate").val();
       if (startDate != '' && endDate !='') {
           if (Date.parse(startDate) > Date.parse(endDate)) {
               $("txttodate").val('');
               alert("Start date should not be greater than end date");
           }
       }
       return false;
   }
 
Share this answer
 
Comments
anurag19289 8-Nov-13 12:08pm    
good1
Hi,

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
C#
Page.RegisterHiddenField("hidden field name", dropdownid.ClientID);


Then in the javascript, get the value of both the dropdowns like
JavaScript
document.getElementById(document.getElementById("hiddenfieldname").value).value


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
 
v2
Comments
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