Explore the community Forums Lectora Lectora Questions & Answers cant find the variable presets Reply To: cant find the variable presets

#377519 Score: 1
Profile photo of Darrel Somoza
Darrel Somoza
Member
contributor
friend finder
beginner
intermediate
junior moderator
advanced
wise owl
curious george
profile
209 pts
@Klaatu

var today = new Date(); // this instantiates the Date object
var thedoc = getDisplayDocument(); // creates a variable out of the getDisplayDocument so you can use thedoc in its place.

var btns = thedoc.getElementsByClassName(“calenderbtn”); // Create an HTML collection (not an array) out of all the elements that were assigned the class calendarbtn. Keep in mind that the order, which is important here, is the order in which the elements appear in the DOM top down. The order in the explorer pane is the same as the order in the DOM. I’ll explain more at the bottom just know for now that if you have the buttons in order in the explorer this will work.

btnids = []; // Declare a new empty array to be used below.

for (var i=0;i<btns.length;i++){// this line loops through each of the items in the btns HTML collection in order
btnids.push(btns[i].id); // this adds each buttons HTML id to the end of the btnid array on each iteration of the loop.
}

// At this point btnid is now an array of all the buttons HTML id’s in the order they appear in the explorer panel.
for (var j=0;j<today.getDate();j++){ // this creates a loop starting with 0 and continues until todays date
window[btnids[j]].setDisabled(false); // This will enable a button by setting its disabled property to false if its position in the array equals the iteration number which will be less than or equal to todays date.
}
Nice job, Tim. Hope I explained it correctly / sufficiently.

Unless you did it for clarity, I would not use a variable (thedoc) in place of the getDisplayDocument method in this case because you’re only using it once; you actually typed more than necessary.

When I was talking about the order above, if you were to move the 24th button just under the 2nd button in the explorer pane you’ll notice that the 24th becomes enables on December 3rd (its new position).

This post has received 1 vote up.