date error alert
i want my date to indicate an error msg to indicaite if an end date is in the past this is the java script i have and it dont seem to work
var
ErrorCount = 0;
var
dteStartDate = GetField("dteStartDate", "");
var
dteEndDate = GetField("dteEndDate", "");
while
(ErrorCount == 0)
{
if
(dteStartDate < dteEndDate)
{
//alerting the user to select a valid time
alert("Please select a valid time that the Audit should start!");
ErrorCount = 1;
break;
}
ErrorCount = 1
}
Comments
-
GetField function returns string, so you don't compare dates, but strings.
If you want to compare dates, you need to convert them to JavaScript dates.
http://www.w3schools.com/js/js_obj_date.asp
Take a look at this JavaScript:var tmpStart = strStartDate.split('.'); var tmpEnd = strEndDate.split('.'); var dtStartDate = new Date(parseInt(tmpStart[2], 10), parseInt(tmpStart[1], 10), parseInt(tmpStart[0], 10)); var dtEndDate = new Date(parseInt(tmpEnd[2], 10), parseInt(tmpEnd[1], 10), parseInt(tmpEnd[0], 10)); if(dtStartDate < dtEndDate) { ... }
This is not robust code which presume, that in strStartDate is date in format d.m.Y (day, month, year, separated by periods). Date is splitted to three integers, which are passed to Date constructor. I guess that you use other date format in your country, so you will need to modify it slightly. Also, end users could use other date format, so client side check might be tricky.
0 -
Is there any reason not to merely set the limit of the date field to today?
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 152 General Questions
- 148 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 32 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 10 XM Fax
- Follow Categories