#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Manchester
    Posts
    15
    Rep Power
    0

    Unhappy javascript timer


    Hi everyone
    my problem:-
    we have a input field for the countdown timer in the header, so its get dispalyed on every page and logs the user out automatically!
    its has a colour background so on other white pages u can c the layer! is it possible to hide this in sum way and only show when timer starts to count down?
    the actually timer does display when there are say only 2 minutes left but i want the layer to do the same thing?

    here is the javascript to the timer:-

    var counter = 0;
    var startTimer = -1;

    function reload() {
    //window.location.href = URL
    }

    function countDown(countdown) {
    // --- Store the time we should start displaying the counter
    if(startTimer == -1)
    { startTimer = countdown/2; }

    counter=countdown;

    if (counter <= startTimer)
    {
    // --- Conver the seconds in to minutes and seconds for display
    minutes=Math.floor(counter/60);
    seconds=counter % 60;

    // --- Pad the seconds (if needed)
    if(seconds < 10)
    { seconds = "0" + seconds; }

    // --- Display the timer
    document.timer.field.value = 'Timeout in:-' + minutes + ':' + seconds + ' ';
    }

    // --- Decrease the seconds counter
    counter-- ;

    // --- Call this method again in 1 second
    if (counter != -1)
    setTimeout('countDown(counter)',1000);
    else
    setTimeout("reload()");
    }





    and in body we have

    <div><form name="timer"><input type="text" class="layer" size="16" value="" name="field" readonly="true"></form>
    <script>countDown({$medVisorConfig.serviceSessionTimeout});</script></div>





    css is:-

    .layer{
    font-family:Verdana, Arial, Helvetica, sans-serif;
    color:#ffffff;
    text-align:left;
    font-weight:bold;
    font-size:70%;
    background-color:#076070;
    layer-background-color:#076070;
    border:none;
    position:absolute;
    top:5px;
    left:460px;

    }

    can anyone help! maybe sumthing to do with hide and show layers or get the input field to display only when timer starts to count down?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    804
    Rep Power
    101
    If you give the div an ID, you should be able to let it be hidden to begin with and then make it visible later...
    Code:
    <HTML>
    <HEAD>
    <SCRIPT>
    function start_timer() {
      // do whatever, and when you want to make it visible, just execute these lines:
      var o = document.getElementById("timer");
      o.innerHTML = "<center>Whatever the timer is going to display...</center>";
      o.style.visibility = "visible";
      // you don't even need a text entry; you can just dynamically change the innerHTML property of the div whenever you want to update the timer.
    };
    </SCRIPT>
    </HEAD>
    
    <BODY onLoad="start_timer();">
    <DIV ID="timer" STYLE="visibility:hidden; background:00ff00">(this text will not be displayed)</DIV>
    </BODY>
    </HTML>
    Since you said you wanted a different background colour, I made it green for an example. You could make it any colour you want. If no colour is specified, it will be transparent, so it really would be fine just to specify white (ffffff) and then although it would look no different on a white page, if the page had a different background the div would still be a white rectangle.
    Last edited by Clone53421; July 4th, 2003 at 04:35 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Manchester
    Posts
    15
    Rep Power
    0
    thanks that worked!
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    804
    Rep Power
    101
    No problem

IMN logo majestic logo threadwatch logo seochat tools logo