Is it possible to test for what day of the week was selected in a Date field using javascript?
I have a script that checks if a "Day" radio button is checked and if so throws an error if the time entered is not between 6:00am and 3:30pm. I need to change the hours to between 6:00am and 2:30pm but only if the day of the week is a Friday (selected in the "Date" field).
Any ideas would really be appreciated.
if
(TimeReceived.isNull == true)
{
xfa.host.messageBox("Please enter a Time Received");
TimeReceived.rawValue
= null;
xfa.host.setFocus("TimeReceived");
}
else if ((TimeofCall.Day.rawValue ==0))
{
if (TimeReceived.rawValue.search(":") > 0)
val1 = TimeReceived.rawValue.replace(":", "");
else
val1 = TimeReceived.rawValue;
if (val1 < 600 || val1 > 1530)
{
xfa.host.messageBox("If 'Time of Call' has Day selected, then the 'Time Received' must be within normal working hours (06:00 to 15:30).Make sure you are using military time, please re-enter.");
TimeReceived.rawValue
= null;
xfa.host.setFocus("TimeReceived");
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
FormCalc has a date function to get the day of the week.
// form1.page1.subform1.dayOfWeek::calculate - (FormCalc, client)
var date_ = Date2Num(date.formattedValue,"MM/DD/YYYY")
$ = Num2Date(date_,"EEE")
The pattern "EEE" returns the Mon, Tue, Wed, etcetera. You have to synch the date pattern on the DateTimeField ("date" in my case) with the script.
"dayOfTheWeek" could be a hidden field and you could reference the "dayOfTheWeek.rawValue" from your JavaScript.
Steve
Views
Replies
Total Likes
FormCalc has a date function to get the day of the week.
// form1.page1.subform1.dayOfWeek::calculate - (FormCalc, client)
var date_ = Date2Num(date.formattedValue,"MM/DD/YYYY")
$ = Num2Date(date_,"EEE")
The pattern "EEE" returns the Mon, Tue, Wed, etcetera. You have to synch the date pattern on the DateTimeField ("date" in my case) with the script.
"dayOfTheWeek" could be a hidden field and you could reference the "dayOfTheWeek.rawValue" from your JavaScript.
Steve
Views
Replies
Total Likes
Steve,
This sounds like exactly what I'm looking for, I'm just struggling a bit to get it working.
Does the "dayOfTheWeek" hidden field (that does the FormCalc) need to be a particular type of field? (Would a text field work?)
You mentioned the need to sync the date pattern on the DateTimeField with the script. Which pattern applies? There is Display, Edit, Validation and Data.
If the "dayOfTheWeek" field is visible for testing purposes, is there a way I can see that the EEE pattern is correctly returning the Day of the Week?
Thanks for helping the noobie on this one.
Views
Replies
Total Likes
I am really getting frustrated with the new forum software. They go to all the effort to enable attachments and it doesn't always work. We would be better off not having it all. Sorry. I digress.
Does the "dayOfTheWeek" hidden field (that does the FormCalc) need to be a particular type of field? (Would a text field work?)
In my sample "dayOfTheWeek" is a textt field and it is not hidden so you can validate the results.
You mentioned the need to sync the date pattern on the DateTimeField with the script. Which pattern applies? There is Display, Edit, Validation and Data.
Display and Validation are defined as "date{MM/DD/YYYY}".
If the "dayOfTheWeek" field is visible for testing purposes, is there a way I can see that the EEE pattern is correctly returning the Day of the Week?
As stated above. Note, you can also use "E" pattern to return an integer (1-7) where 7 is Sunday, if you prefer.
Steve
Views
Replies
Total Likes
Steve,
I did notice that your original post has an attachment, but it says "QUEUED" and I have not been able to download it.
I was able to get things working perfectly however with the additional info you provided in your last post.
Thanks so much, I really appreciate the help on this!
- Kevin
Views
Replies
Total Likes
Steve,
Can I ensure that the user chooses a certain day (e.g. SUN).
I want the field to be invisible and yet that an error message will appear.
Thanks,
Yaniv
Views
Replies
Total Likes
You could change the PDF, attached to this thread, as follows:
1) change the presence of 'dayOfTheWeek' to hidden
2) add the script, below, to the validate event of 'dayOfTheWeek'
// form1.page1.subform1.dayOfWeek::validate - (JavaScript, client)
if (this.rawValue != "Sun") {
xfa.host.messageBox("The selected date is not a Sunday.");
}
Steve
Views
Replies
Total Likes
Thank you so much Steve. I have changed the 'dayOfTheWeek' to hidden and added your script to the validate event of 'dayOfTheWeek' and it works.
The error message, though, appears as soon as the user opens the document. Is there a way to make this error message pop up only after the user has attempted to enter a correct date?
Yaniv
Views
Replies
Total Likes
Whoops. Try this instead. It will test the presence of a value before testing the day.
// form1.page1.subform1.dayOfWeek::validate - (JavaScript, client)
if (this.rawValue != "Sun") {
xfa.host.messageBox("The selected date is not a Sunday.");
}
}
Views
Replies
Total Likes
Works!
Thnak you!
Yaniv
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies