Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2012
    Thanked 0 Times in 0 Posts

    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);
    ****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>

  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 726 Times in 715 Posts
    Change the value you are setting this.container.innerHTML to so that it includes the link.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts