Click here to Skip to main content
14,486,942 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

i think this will help you

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

Check the Operator and Type Property
   
v2
Comments
Vani Kulkarni 26-Jun-12 0:32am
   
Good answer 5!
Rate this:
Please Sign up or sign in to vote.

Solution 3

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[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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;
   }
   
Comments
anurag19289 8-Nov-13 12:08pm
   
good1
Rate this:
Please Sign up or sign in to vote.

Solution 2

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


Then in the javascript, get the value of both the dropdowns like
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 :)
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100