Mr Kremer,
I believe you taught me something today regarding scripting. I have been trying to learn more and more everyday. The thing is about reading books is understanding and relating what I'm reading to what I'm trying to do. I find it so daunting and confusing. I read all the links and references I receive, but at times it makes me overwhelmed. But, I stick with it with the hopes of something getting into the brain pan. And, at times it does. This is what got thru.
This is the script I came up with, with your help and guidance. To my own surprise, I got it. This works: Did I get it correct?
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var theDay = "";
var theYear = "";
// get the information from the "theDate" field
var theDate = this.getField("theDate").valueAsString;
if (theDate != "") {
// convert the date string to a JavaScript Date object
var d = util.scand("mmmm,dd,yyyy", theDate);
if (d != null) {
theMonth = monthNames[d.getMonth()];
theDay = d.getDate();
theYear = d.getFullYear();
}
}
event.value = theMonth;
this.getField("Day").value = theDay;
this.getField("Year").value = theYear;
this.getField("Month").value = theMonth;
Thank you for the invaluable time you spend helping people and myself. I really appreciate it.
I completely understand, programming is hard, and it requires a different way of thinking.
You are almost there. It may work, but there are two issues I see that might bite you later.
The first one is that you should "declare" the "theMonth" variable (which was in my original script, but you probably removed it when you added the array of month names. You are already declaring (and initializing) the variables "theDay" and "theYear", so just add this line to these two:
var theMonth = "";
And, then at the end you can remove one line - this is the calculation script for the "theMonth" field, which means that we do not have to set the value of the field via 'this.getField("theMonth").value' - because it is a calculation script, you set the value of the calculated field using the 'event.value' property. So, remove this line from the end of your script:
this.getField("Month").value = theMonth;That should do it.