Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-29-2012, 09:46 PM   PM User | #1
ted.johnson0988
New Coder

 
Join Date: May 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
ted.johnson0988 is an unknown quantity at this point
Can I make a changing hyperlink?

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);
****this.calculate();
}
*
DayCounter.prototype.calculate=function(){
****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'); }
*
</script>
</head>
<body>
<div id="counter">The contends of this DIV tag will be replaced by the counter</div>
</body>
ted.johnson0988 is offline   Reply With Quote
Old 05-29-2012, 09:53 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Change the value you are setting this.container.innerHTML to so that it includes the link.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
hyperlink, link, url

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Advertisement
Log in to turn off these ads.