  | 
              
	              
	                
  
    
	 
        สอบถามปัญหาคำสั่ง JavaScript timer ตัวจะเขียนคำสั่งหยุดเวลาอย่างไรครับ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                สอบถามปัญหาคำสั่ง JavaScript timer ตัวจะเขียนคำสั่งหยุดเวลาอย่างไรครับ 
 
 
 
Code (PHP) 
<?php
session_start();
/* If you refresh the page
   or
   leave the page to browse and come back
   then the timer will continue to count down until finished. */
   
// $minutes and $seconds are added together to get total time.
$minutes = 20; // Enter minutes
$seconds = 0; // Enter seconds
$time_limit = ($minutes * 60) + $seconds + 1; // Convert total time into seconds
if(!isset($_SESSION["start_time"])){$_SESSION["start_time"] = mktime(date(G),date(i),date(s),date(m),date(d),date(Y)) + $time_limit;} // Add $time_limit (total time) to start time. And store into session variable.
?>
<html>
<head>
</head>
<body>
<input id="txt" readonly>
<script>
var ct = setInterval("calculate_time()",100); // Start clock.
function calculate_time()
{
 var end_time = "<?php echo $_SESSION["start_time"]; ?>"; // Get end time from session variable (total time in seconds).
 var dt = new Date(); // Create date object.
 var time_stamp = dt.getTime()/1000; // Get current minutes (converted to seconds).
 var total_time = end_time - Math.round(time_stamp); // Subtract current seconds from total seconds to get seconds remaining.
 var mins = Math.floor(total_time / 60); // Extract minutes from seconds remaining.
 var secs = total_time - (mins * 60); // Extract remainder seconds if any.
 if(secs < 10){secs = "0" + secs;} // Check if seconds are less than 10 and add a 0 in front.
 document.getElementById("txt").value = mins + ":" + secs; // Display remaining minutes and seconds.
 // Check for end of time, stop clock and display message.
 if(mins <= 0)
 {
  if(secs <= 0 || mins < 0)
  {
   clearInterval(ct);
   document.getElementById("txt").value = "0:00";
   alert("The time is up.");
   }
  }
 }
</script>
</body>
</html>
 
 
 
 
ผมต้องการให้เวลาหยุดก่อนที่เวลาจะหมดเอง ต้องเขียนโค้ดยังไงครับ อย่างเช่น พอกดปุ่ม submit แล้วให้เวลา หยุดค้างไว้ หรือปรับเป็น 0.00 แต่อยากให้เวลาค้างไว้ โดยไม่เปลี่ยนไปหน้าอื่นนะครับ 
ขอแบบเป็นโค้ดแล้วอธิบายด้วยนะครับ ผมไม่ค่อยรู้เกี่ยวกับภาษา  
 
ขอบคุณล่วงหน้าครับ 
^-^
 
 
  Tag : PHP, MySQL, JavaScript, Win (Windows App)               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2011-10-10 23:41:42	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2011-10-10 23:34:06 | 
                      By :
                          39boy | 
                      View :
                          2974 | 
                      Reply :
                          11 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ครับพี่ win ผมอ่านกระทู้แล้วพอได้แนวทางบ้าง ขอบคุณครับ 
 
แต่พอผมลองเรียก function อีกตัวหนึ่งขึ้นมาเพื่อ หยุดทำสั่ง แต่ไม่ได้ผลช่วยดูที่ครับควรปรับแก้ตรงไหน 
คำสั่ง แสดงผลเป็น 0.00 ตามด้วย The time stop แต่พอกด OK ออกไป ทำไมเวลายังกลับมาทำงานต่อจน หมดไปเองครับ 
 
 
//////// 
 function stop_time() 
  { 
  	if(document.myform.onClick = true) 
  	{ 
  	clearInterval(ct); 
  	 document.getElementById("txt").value = "0:00"; 
  	 alert("The time stop."); 
  	} 
  } 
////// 
 
ผมวางไว้ต่อจากฟังก์ชันเดิมเลย                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-10-11 19:00:59 | 
                        By :
                            39boy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ขอบคุณครับ แต่ยังรอคนช่วยอยู่นะครับ  
 
 jQuery Effects : jQuery and Effects 
 
ยิ่งหนักกว่าเดิมอะครับ                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-10-13 00:33:32 | 
                        By :
                            39boy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ผมติดตั้ง jQuery ไม่เป็นครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-10-13 11:47:27 | 
                        By :
                            39boy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 อ่อ ได้แล้วนะครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-10-13 11:58:05 | 
                        By :
                            39boy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ขอบคุณครับ บอท กับ webmaster 
โอกาสหน้าจะมารบกวนอีกนะครับ                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-10-14 00:06:49 | 
                        By :
                            39boy | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |