Highlighted
Absent Member.
Absent Member.
4383 views

How to validate Date fields using Java script


Hi, I need to compare the current date with a date field on form (date/time type field), and prompt the user if the user entered date value is less than current date. I wrote this script, which works fine in Preview mode, but not working in deployed mashup.

Here is the script. I am calling the function properly. Please help me to fix the issue.

function TargetDateChanged() {

var CDate, TDate;

CDate = new Date();

var nCDate = CDate.valueOf();

TDate = GetFieldValue("TARGET_DATE");

var nTDate = TDate.valueOf();

nTDate = nTDate+100

if(nTDate < nCDate) {

alert('Target Date should be greater than Current Date');

SetFieldValue("TARGET_DATE", "", "true");

MakeFieldRequired("TARGET_DATE", true);

}

else {

MakeFieldValid(trgDbName);

}

}
0 Likes
6 Replies
Highlighted
Not applicable

Re: How to validate Date fields using Java script


you probably need to create a couple of event handlers and have it call your code such an Onload event and a onchange callback - not sure of the exact syntax at this time but if you search for it in the forum you should find the syntax
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to validate Date fields using Java script


Hi Mike,

I have this function call, lplease let me know what else I can do fix ths issue. Do you think the logic I used in the script is syntactically correct or not.

AddChangeCallback("TARGET_DATE", TargetDateChanged);
0 Likes
Absent Member.
Absent Member.

Re: How to validate Date fields using Java script


You may want to try clearing the browser cache and restarting IIS on the web server. I've had similar issues where javascript didn't run correctly until IIS was restarted.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to validate Date fields using Java script


Thanks for your input, I will try it and get back with an update.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to validate Date fields using Java script


No Luck, could you please try and give me the code that is working.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to validate Date fields using Java script


Have you tried using Firefox with Firebug? For debugging Javascript it's invaluable. Set a breakpoint in your function (to establish a context), switch to Console, and enter your statements one-at-a-time to see what happens. I have always been frustrated by date handling in Javascript.

To echo what Peter mentioned, there can be some challenges with Javascript caching, especially if you're running a clustered or load-balanced env. IISRESET is your friend 🙂
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.