Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Logic In a loop/if statement
    text
    copied!<p>I have this function (transComplete) which performs the task of highlighting a relevant indicator showing the user which page they are on, each element of these controllers/indicators represents a page and will highlight appropriately.</p> <p>This works independently however when I introduce a click function that allows to interact with indicators to move between pages it navigates correctly but does not highlight as needed (works only every two clicks) which leads me to believe its a logic issue in my code.</p> <p>The boolean logic of true/false is the cause, the highlighting only occurs on the 'true' cases of the variable "isOnSecond" so I essentially need a solution that always highlights the relevant controller when clicked</p> <p>The main function is below: </p> <p>function transComplete() {</p> <pre><code>slideTransStep = 0; crtSlideIndex = nextSlideIndex; // for IE filters, removing filters re-enables cleartype if (nextSlide.style.removeAttribute) { nextSlide.style.removeAttribute("filter"); // show next slide showSlide((crtSlideIndex &gt;= totalSlides) ? 1 : crtSlideIndex + 1); //Highlights a nav circle every two transitions as the boolean alternates if (isOnSecond == true) { //unhighlight all controls for (var i = 0; i &lt; slidesControllersCollection.length; i++) { if (slidesControllersCollection[i].className === slideHighlightClass) { slidesControllersCollection[i].className = ""; } // highlight the control for the next slide document.getElementById("slide-control-" + crtSlideIndex).className = slideHighlightClass; } isOnSecond = false; } else { isOnSecond = true; } } </code></pre> <p>The onclick Function:</p> <pre><code> function clickSlide(control) { showSlide(Number(control.id.substr(control.id.lastIndexOf("-")+1)),true); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload