Results 1 to 2 of 2

Thread: Online Quiz

  1. #1
    Join Date
    Jul 2009
    Location
    Washington (USA)
    Posts
    94
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Online Quiz

    Hi

    I have been trying to make an online quiz for my site. However, I have had some troble adding the score with JS. Here's what I got so far...

    Code:
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <script>
    var total = 0;
    
    
    if (document.test.q1 === 'correct') {
    total = total + 5;
    }
    else {
    total = total + 0;
    }
    
    
    </script>
    <form name="test">
    <div id="q1">
    <b>[1] HTML stands for:</b><br><br>
    <input type="radio" name="q1" value="correct">Hyper Text Markup Language<br>
    <input type="radio" name="q1" value="wrong">Hyper Tool Markup Language<br>
    <input type="radio" name="q1" value="wrong">Hyper Text Transfer Prodical<br>
    <input type="radio" name="q1" value="wrong">Hyperlinks &amp; Text Mulnipulation Language<br>
    <div align="right"><button onClick="showhide('results'); return(false);">Next</button></div>
    </div>
    
    <div id="results" style="display:none;">
    <center><h1>You've Finished!</h1>
    You Scored: <font color="red"><script>document.write(total);</script>%</font><br>
    
    <script>
    if (total>85) {
    document.write("You should be proud!");
    }
    else if (total<85) {
    document.write("Keep working on it!");
    }
    else {
    document.write("");
    }
    </script>
    
    </center></div>
    </form>
    </body>
    </html>
    Can anyone help me?

  2. #2
    Join Date
    Oct 2009
    Posts
    38
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default

    first of all, what exactly do you want to do this code..explain better!!
    and second of all, your code has many mistakes!!

    i tried and solved some of them..here is the code, but i want you to tell me exactly what you want to do that code so i can help you more!!

    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">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Test</title>
    </head>
    <body>
    
    <form name="test" method="get" action="">
    	<div id="q1">
    		<table border="0" cellspacing="0" cellpadding="0">
    			<tr>
    				<td><b>[1] HTML stands for:</b>
    				<br/><br/></td>
    			</tr>
    			<tr>
    				<td><input type="radio" name="q1" value="correct">Hyper Text Markup Language</input></td>
    			</tr>
    			<tr>
    				<td><input type="radio" name="q1" value="wrong">Hyper Tool Markup Language</input></td>
    			</tr>
    			<tr>
    				<td><input type="radio" name="q1" value="wrong">Hyper Text Transfer Prodical</input></td>
    			</tr>
    			<tr>
    				<td><input type="radio" name="q1" value="wrong">Hyperlinks &amp; Text Mulnipulation Language</input>
    				<br/><br/></td>
    			</tr>
    			<tr>		
    				<td align="right"><input type="button" onClick="showhide();document.getElementById('results').style.display='block';" value="Next"/></td>
    			</tr>
    		</table>
    	</div>
    </form>
    
    <div id="results" style="display:none;" align="center">
    	<h1>You've Finished!</h1>
    	You Scored:<font color="red"><script>document.write(total);</script>%</font><br/>
    
    	<script>	
    		var total = 0;
    		
    		if(document.getElementById('q1').getElementsByTagName('input').value == 'correct') {
    			total = total + 5;
    		}
    		else {
    			total = total + 0;
    		}
    
    		function showhide() {
    			if (total>85) {
    				document.write("You should be proud!");
    			}
    			else if (total<85) {
    				document.write("Keep working on it!");
    			}
    			else {
    				document.write("");
    			}
    		}
    	</script>
    </div>
    
    </body>
    </html>

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
  •