how to stop the time function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shyamg
    New Member
    • Jun 2007
    • 28

    #1

    how to stop the time function

    here iam using in my page time text field when page is the time is runing
    ok its fine but when page is loded ofter the time will be stoped how....its posible ...plz tell me i want only the display time only the page loding time.

    this is my script
    Code:
                
            function det_time()
       {
       var d = new Date();
       var c_hour = d.getHours();
       var c_min = d.getMinutes();
       var c_sec = d.getSeconds();
       var t = c_hour + ":" + c_min + ":" + c_sec;
       document.all.ctime.value = t;
       
       
       }
    
    setInterval("det_time()", 1000);
                
                
    	</script>

    <td width="18%" class="labeltex t">Creation Time</td>

    <td width="45%" class="blanktex t"><html:tex t property="ctime " styleClass="tex t" size="10" maxlength="30" value="${U45.ct ime}"readonly=" true"/> </td>


    ss
  • vituko
    New Member
    • Dec 2006
    • 48

    #2
    setInterval returns an integer reference, you must store it.
    Then, you can call clearInterval with this value as argument. From an event, for example.

    Int_ref = setInterval (...) ;
    clearInterval (Int_ref) ;

    Comment

    • shyamg
      New Member
      • Jun 2007
      • 28

      #3
      Originally posted by vituko
      setInterval returns an integer reference, you must store it.
      Then, you can call clearInterval with this value as argument. From an event, for example.

      Int_ref = setInterval (...) ;
      clearInterval (Int_ref) ;

      hallo this is not working i have to write like this

      Code:
         function det_time()
         {
         var d = new Date();
         var c_hour = d.getHours();
         var c_min = d.getMinutes();
         var c_sec = d.getSeconds();
         var t = c_hour + ":" + c_min + ":" + c_sec;
         document.all.ctime.value = t;
          var Int_ref = setInterval (t) ;
          clearInterval (Int_ref);
      
         
         }

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        this is to start immediatly when the page is parsed:

        [CODE=javascript]function det_time() {
        // some code
        }

        var interval = window.setInter val(det_time, 10);[/CODE]

        and then you have to call in the body's onload:

        [HTML]<body onload="window. clearInterval(i nterval);">[/HTML]
        kind regards

        Comment

        • shyamg
          New Member
          • Jun 2007
          • 28

          #5
          hi gits ...


          i want to stop the clock when the page is loding that time only run then its stop that time i want only using a text field in creation time .....that page loding time ..only


          ss

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            ??? you want to display the time from start of loading a page until it is loaded (and that is the moment when the body's onload fires!!) ... ??? in case i'm wrong please explain it in more detail ... what you want to do exactly. when do you want to call det_time the first time? when do you want to stop the interval? what do you want to display do you mean the time that the page needed to be loaded or the time when the page was loaded ... means: i want to view it 12:30 pm ... click a link or something ... and you want to display 12:30 pm now? ...

            kind regards

            Comment

            • shyamg
              New Member
              • Jun 2007
              • 28

              #7
              Originally posted by gits
              ??? you want to display the time from start of loading a page until it is loaded (and that is the moment when the body's onload fires!!) ... ??? in case i'm wrong please explain it in more detail ... what you want to do exactly. when do you want to call det_time the first time? when do you want to stop the interval? what do you want to display do you mean the time that the page needed to be loaded or the time when the page was loaded ... means: i want to view it 12:30 pm ... click a link or something ... and you want to display 12:30 pm now? ...

              kind regards
              hi gits..


              i want when ever jsp page is loded .it will be loded that time its time is runing i want fix that time when the page is loded that time only fix.ofter that time is stop but in my using text field in that time is continusly runing /........

              Comment

              • shyamg
                New Member
                • Jun 2007
                • 28

                #8
                [HTML]<html>
                <head>


                </head>
                <body>

                <FORM NAME="myform">
                <INPUT TYPE="TEXT" SIZE="10" MAXLENGTH="10" VALUE=""
                NAME="my_time">
                </FORM>
                <SCRIPT LANGUAGE="JAVAS CRIPT">

                function det_time()
                {
                var d = new Date();
                var c_hour = d.getHours();
                var c_min = d.getMinutes();
                var c_sec = d.getSeconds();
                var t = c_hour + ":" + c_min + ":" + c_sec;
                document.myform .my_time.value = t;
                }

                setInterval("de t_time()", 1000);


                </SCRIPT>


                </body>
                </html>[/HTML]

                this is my code in this when the page is loded the time will be stoped how.
                Last edited by gits; Aug 21 '07, 11:57 AM. Reason: added code tags

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  hi ...

                  i added something to your code ... and you may see how to stop an interval:

                  [HTML]
                  <html>
                  <head>
                  </head>
                  <body>
                  <FORM NAME="myform">
                  <INPUT TYPE="TEXT" SIZE="10" MAXLENGTH="10" VALUE="" NAME="my_time">
                  <input type="button" value="stop_tim e" onclick="clearI nterval(interva l_ref);"
                  </FORM>
                  <SCRIPT LANGUAGE="JAVAS CRIPT">
                  function det_time()
                  {
                  var d = new Date();
                  var c_hour = d.getHours();
                  var c_min = d.getMinutes();
                  var c_sec = d.getSeconds();
                  var t = c_hour + ":" + c_min + ":" + c_sec;
                  document.myform .my_time.value = t;
                  }
                  var interval_ref = setInterval("de t_time()", 1000);
                  </SCRIPT>
                  </body>
                  </html>
                  [/HTML]

                  as far as i understand you ... you don't need the interval ... simply call det_time in the onload-handler of your page, so the textfield shows the current time when the page is loaded ...

                  kind regards

                  ps: please use code tags when posting code

                  Comment

                  Working...