• Timer in PHP/Javascript

    Timer in PHP/Javascript

    Timer in PHP/Javascript

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    
    <script type="text/javascript" language="javascript">// <![CDATA[
    var mins
    var secs;
     
    function cd() {
         mins = 1 * m("1"); // change minutes here
         secs = 0 + s(":00"); // change seconds here (always add an additional second to your total)
         redo();
    }
     
    function m(obj) {
         for(var i = 0; i < obj.length; i++) {
              if(obj.substring(i, i + 1) == ":")
              break;
         }
         return(obj.substring(0, i));
    }
     
    function s(obj) {
         for(var i = 0; i < obj.length; i++) {
              if(obj.substring(i, i + 1) == ":")
              break;
         }
         return(obj.substring(i + 1, obj.length));
    }
     
    function dis(mins,secs) {
         var disp;
         if(mins <= 9) {
              disp = " 0";
         } else {
              disp = " ";
         }
         disp += mins + ":";
         if(secs <= 9) {
              disp += "0" + secs;
         } else {
              disp += secs;
         }
     
         return(disp);
    }
     
    function redo() {
     
         secs--;
         if(secs == -1) {
              secs = 59;
              mins--;
         }
         document.cd.disp.value = dis(mins,secs); // setup additional displays here.
         if((mins == 0) &#038;&#038; (secs == 0)) {
              window.alert("Time is up. Press OK to continue."); // change timeout message as required
              window.location = "index.php" // redirects to specified page once timer ends and ok button is pressed
         } else {
             cd = setTimeout("redo()",1000);
         }
    }
     
    function init() {
      cd();
    }
     
    function start() {
      return init();
    }
    // ]]></script>
    1
    
    <input onclick="return start();" type="button" value="Start" />
    Tags:

Comments on this post

Leave a Reply

  • Security Code :


    2 + four =