These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Auto populate months if statement

paulaeddy
Registered: May 14 2010
Posts: 22

I have an set of 12 fields that populate months.
 
The first field (Month 1) is populated with the first month.
 
The second (Month 2) field contains the script (below) that populates itself and the remaining fields with the remaining months.
 
There is a separate field (NumberMonths) which caculates how many months should be populated. How can I revised the second field script to only populate a certain number of months while leaving (or changing if already populated with a previous entry) the remaining fields to blank.
 
For example, if "NumberMonths" is 5 and "Month 1" is May, then I only need June, July, August, and September to populate the next 4 fields and the remaining fields to be blank.
 
Thanks for your help!
 
"Month 2" Script:

var sInputMonth = getField("Month 1").value;
var aMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var iStartMonth = aMonths.indexOf(sInputMonth);
if(iStartMonth < 0) {
app.alert("Error! Invalid Month.");
}
else {
var y = 2;
var x = iStartMonth + 1;
while(x != iStartMonth) {
if(x > 11)
x = 0;
else {
getField("Month " + y.toString()).value = aMonths[x];
y++;
x++;
}
}
}

My Product Information:
Acrobat Pro 9.4.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You might want to look at using a "for" loop or a 'while' statement to control the execution and branching of your code.

George Kaiser

paulaeddy
Registered: May 14 2010
Posts: 22
Sadly, I'm not sure how to do that. Can you help? Thanks.