Results 1 to 2 of 2

Thread: [beginner] Looking for help

  1. #1
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [beginner] Looking for help

    I am a beginner learning Javascript. I try to use alert boxes to alert the users, also, i try to set a hidden timer in my page. But all the codes are not working in my page especially the timer.
    Please help me to solve this.

    Code:
    <script type="text/javascript">
    		
    		var d=new Date();
    		var time=d.getHours();
    		
    		if (time <=12){
    				alert("Good Morning! Please enter your name and fill in all the questions.");
    			}
    				
    		else if(time >12 && time <18){
    				alert("Good Afternoon! Please enter your name and fill in all the questions.");
    			}
    				
    		else{
    				alert("Good Evening! Please enter your name and fill in all the questions.");
    			}
    			
    		var start_time, end_time, time_spent, k;
    		
    		
    		function startTimer(){	
    			k = new Date();
    			start_time = k.getTime();
    			alert("The timer is started! Please answer the questions ASAP!!");
    		}
    		
    		
    		function stopTimer(){	
    			k = new Date();
    			end_time = k.getTime();
    			time_spent = end_time - start_time;
    			alert("you had used " .time_spent. " to finish this form.");
    			
    			document.getElementById("hidden_timer").value = time_spent; 
    		}
    		
    		function validateForm() {
    			var x=document.forms["quizform"]["username"].value;
    			
    			if (x =="" || x ==null){
    				alert("Please enter your name.");
    				return false;
    			}
    			else{	
    				return confirm("Are you sure to send the form?");
    			}
    		}		
    		</script>

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,800
    Thanks
    2
    Thanked 421 Times in 415 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
            </head>
    
    <body>
    <form name="quizform" >
     <input name="username" />
     <input id="hidden_timer"  />
     <input type="button" name="" value="validateForm()" onclick="validateForm();"/>
    </form>
    <script type="text/javascript">
    
    		var d=new Date();
    		var time=d.getHours();
    
    		if (time <=12){
    				alert("Good Morning! Please enter your name and fill in all the questions.");
    			}
    
    		else if(time >12 && time <18){
    				alert("Good Afternoon! Please enter your name and fill in all the questions.");
    			}
    
    		else{
    				alert("Good Evening! Please enter your name and fill in all the questions.");
    			}
    
    		var start_time;
    
    
    		function startTimer(){
    			start_time = new Date().getTime();
    			alert("The timer is started! Please answer the questions ASAP!!");
    		}
    
    
    		function stopTimer(){
    			var time_spent = new Date().getTime() - start_time;
    			alert("you had used "+time_spent+" to finish this form.");
    
    			document.getElementById("hidden_timer").value = time_spent;
    		}
    
    		function validateForm() {
    			var x=document.forms["quizform"]["username"].value;
    
    			if (x ==""){
    				alert("Please enter your name.");
    				return false;
    			}
    			else{
                    stopTimer();
    				return confirm("Are you sure to send the form?");
    			}
    		}
    
            startTimer()
    		</script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. im a php beginner
    By Soft Devil in forum PHP
    Replies: 1
    Last Post: 05-04-2008, 04:17 PM
  2. PHP and CSS? (Beginner)
    By rpflorence in forum PHP
    Replies: 4
    Last Post: 01-21-2008, 03:28 AM
  3. Beginner DOM
    By pcbrainbuster in forum JavaScript
    Replies: 14
    Last Post: 02-28-2007, 03:27 PM
  4. beginner to CSS
    By gell in forum CSS
    Replies: 2
    Last Post: 01-15-2007, 05:39 AM
  5. Help a beginner
    By costas in forum Graphics
    Replies: 10
    Last Post: 09-29-2006, 03:28 AM

Bookmarks

Posting Permissions

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