Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am unable to select any date due to this check
JavaScript
function DateCheck(element, name) {

var dateString1 = (document.getElementById("<%= txtActiveTillDate.ClientID %>").value);
var active = new Date(dateString1).getDate() + "-" + new Date(dateString1).getMonth() + "-" + new Date(dateString1).getFullYear();
var dateString2 = (document.getElementById("<%= txtPublishingDate.ClientID %>").value);
var publishing = new Date(dateString2).getDate() + "-" + new Date(dateString2).getMonth() + "-" + new Date(dateString2).getFullYear();
var todaydate = new Date().getDate() + "-" + new Date().getMonth() + "-" + new Date().getFullYear();
if (active < todaydate) {
alert('Active Till date must be greater than Today date.');
document.getElementById("<%= txtActiveTillDate.ClientID %>").value = "";
return;
}
if (publishing < todaydate) {
alert('Publishing date must be greater or equal to Today date.');
document.getElementById("<%= txtPublishingDate.ClientID %>").value = "";
return;
}
if (publishing >= active) {
alert('Active Till Date cannot be less than Publishing Date.');
document.getElementById("<%= txtActiveTillDate.ClientID %>").value = "";
return;
}
}
Posted
Updated 4-Feb-15 20:59pm
v2
Comments
Sinisa Hajnal 5-Feb-15 2:50am    
Please use Improve question to add more details. You're just stating you cannot select date without explaining frmo where you're selecting, HOW are you selecting, what you get from your script, what you're expecting etc...we don't see your screen, know your project or its goal. You have to describe the problem in detail.

That said, I would (and do) use moment.js library for all date problems in javascript. There are few others such as Date.js. Good luck.
Neha Mukesh 5-Feb-15 4:38am    
I have two text boxes namely txtActiveTill and txtPublishing
Date and i want to compare dates in these two textboxes that i have been taking from calendar control and i want to check that these values from today date

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