Bookmark every Second page from an Array
We have some buildings that used to require a one page inspection sheet to be filled out per month.
My previous JavaScript built an array of all our buildings, and whenever one didn't participate, I just "commented" it out of the array before running the JavaScript to bookmark all the pages that did participate.
After they added a second sheet to this inspection, I tried to retrieve the buildings from that array to bookmark every SECOND page (for example, pages 1, 3, 5, 7, etc.). Although it works, the JavaScript also duplicates that same bookmark with another one tagged "undefined."
Could somebody point out my error?
/* Create Bookmarks */
//
// Bookmarks every OTHER page of this document from a defined Array.
//
// Define the Array named aBookmarks.
aBookmarks = new Array(
"Building 01",
"Building 02",
"Building 03",
"Building 04",
"Building 05",
"Building 06",
"Building 07",
"Building 08",
"Building 09",
"Building 10",
"Building 11",
"Building 12",
"Building 13",
"Building 14",
"Building 15",
"Building 16");
// Book every SECOND page from the above array.
var root = this.bookmarkRoot;
// i = Consecutive order of the array.
// n = Total number of pages.
// p = Consecutive order of the pages being bookmarked.
var n = this.numPages;
try {
for (var i = 0; i < n; i){
for (var p = 0; p < n; p){
{
root.createChild(aBookmarks, "this.pageNum=" + p, p)
var i = i + 1;
var p = p + 2
}}}}
// Notify user of possible errors.
catch(e)
{
app.alert("Processing error: "+e)
}
