Indefinitely returning the next Monday, Wednesday and Friday with Javascript or PHP -
i want indefinitely print next monday, wednesday , friday on webpage.
at moment using javascript unsure how proceed days of following weeks.
function nextmon(date) { var ret = new date(date||new date()); ret.setdate(ret.getdate() + (1 - 1 - ret.getday() + 7) % 7 + 1); return ret; } function nextwed(date) { var ret = new date(date||new date()); ret.setdate(ret.getdate() + (4 - 1 - ret.getday() + 7) % 7 + 1); return ret; } function nextfri(date) { var ret = new date(date||new date()); ret.setdate(ret.getdate() + (5 - 1 - ret.getday() + 7) % 7 + 1); return ret; } function nextsession(date){ var today = new date(date||new date()); //monday - wednesday if(today.getday() >= 1 && today.getday() < 3){ return nextwed(); } //wednesday - friday else if(today.getday() >= 3 && today.getday() < 5){ return nextfri(); } else{ return nextmon(); } } setinterval(function(){ for(var = 0; < document.getelementsbyclassname("circlebase").length; i++){ var day = new date(); day.setdate(day.getdate()+i); document.getelementsbyclassname("circlebase")[i].innerhtml = nextsession(day).todatestring(); } }, 1000);
the issue above code prints same week day couple times until loop reaches next weekday in nextsession. html code dates show is:
<div class="inner"> <div class="circlebase"></div> <div class="circlebase"></div> <div class="circlebase"></div> <div class="circlebase"></div> <div class="circlebase"></div> <div class="circlebase"></div> <div class="circlebase"></div> </div>
also there more efficient way of making indefinite div's of same class?
any feedback appreciated
Comments
Post a Comment