View Full Version : Can I make a changing hyperlink?

05-29-2012, 10:46 PM
Hello all,

I'm using a javascript "daily counter" (the code for which is at the bottom) and I'm trying to make it into a link. However, I want that link to change every day depending on what the counter reads. (e.g. I want it to link to "/tagged/DAY-10/" with the DAY-10 being the thing that changes each day and the tagged being constant.)
Now, my basic understanding of HTML lets me know that if I try to code it in as "/tagged/'counter'" or something of that nature which is named in the javascript, it simply won't work.

So, my question is, is there any way I make it into a link that changes retroactively?

Thanks so much.

<title>JavaScript Day Counter - Praveen Lobo</title>

<script type="text/javascript">
* Day Counter script by Praveen Lobo (http://PraveenLobo.com/techblog/java...er-count-days/)
* This notice MUST stay intact(in both JS file and SCRIPT tag) for legal use.
* http://praveenlobo.com/blog/disclaimer/
function DayCounter(initDate, id){
****this.beginDate = new Date(initDate);
****this.container = document.getElementById(id);
****var secDiff = Math.round(((new Date()) - this.beginDate)/1000);
****var nextUpdate = 86400 - (secDiff % 86400);
****var tmp = (tmp = secDiff/86400) < 1? 0 : Math.floor(tmp);
****var days = (tmp < 10 ? ("" + tmp) : tmp < 100 ? ("" + tmp) : tmp);
****this.container.innerHTML =
********"Day " + days ;
****var self = this;
****setTimeout(function(){self.calculate();}, (++nextUpdate*1000));
window.onload=function(){ new DayCounter('May 19, 2012 00:00:00', 'counter'); }
<div id="counter">The contends of this DIV tag will be replaced by the counter</div>

05-29-2012, 10:53 PM
Change the value you are setting this.container.innerHTML to so that it includes the link.