I have two date field viz from-date and to-date
and i want to validate that from-date should be less than or equal to to-date
using javascript.
Note: date field should be in yy-mm-dd format
How is that possible ?
Please help me..
Thanks in advance..
JS date range validation ??
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
I got my problem solved as:
Code: Select all
//find out the current date in Y-m-d format
var currentTime = new Date();
var thisYear = currentTime.getFullYear();
var thisMon = currentTime.getMonth()+1;
var thisDay = currentTime.getDate();
var ymd = thisYear+"-"+thisMon+"-"+thisDay;
//get the value from date field
var selYmd = document.getElementById("from/to").value;
if(selYmd < ymd)
{
alert("Error message goes here..");
return false;
}