By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Show how many answers are correct on clicking a button

P: 4
I want to creat a post like this blog:
http://onlinetoefltest.blogspot.com/...-lesson-1.html

When you chose all the answers and click show answer a msg box will appear and tells how many answers are correct

I view the blog source and copied all the code to my post but it didn't work when i click the show answer button in my post.

Can any one help me with the code?
Thanks in advance

[html]1. Upon hatching, ________. <input id="text1" style="visibility: hidden; width: 1px;" value="A"><br /><input id="choice1A" value="A" name="choice1" type="radio"><label id="C1A">(A) young ducks know how to swim</label><br /><input id="choice1B" value="B" name="choice1" type="radio"><label id="C1B">(B) swimming is known by young ducks</label><br /><input id="choice1C" value="C" name="choice1" type="radio"><label id="C1C">(C) the knowledge of swimming is in young ducks</label><br /><input id="choice1D" value="D" name="choice1" type="radio"><label id="C1D">(D) how to swim is known in young ducks</label><br />2. Some of the rainwater from clouds evaporates before ________. <input id="text2" style="visibility: hidden; width: 1px;" value="A"><br /><input id="choice2A" value="A" name="choice2" type="radio"><label id="C2A">(A) reaching the ground</label><br /><input id="choice2B" value="B" name="choice2" type="radio"><label id="C2B">(B) to reach the ground</label><br /><input id="choice2C" value="C" name="choice2" type="radio"><label id="C2C">(C) reach the ground</label><br /><input id="choice2D" value="D" name="choice2" type="radio"><label id="C2D">(D) the ground reaches</label><br /><input language="javascript" id="button1" onclick="button1_onclick();" value="Show answers" name="button1" type="button">
[/HTML]



Expand|Select|Wrap|Line Numbers
  1. <script id="clientEventHandlersJS" language="javascript">
  2.  
  3. function button1_onclick() {
  4.  
  5. var correct,Total;
  6.  
  7. Total=0;
  8.  
  9. correct= 0;
  10.  
  11. oElement = document.getElementById("choice1A");
  12. if (oElement) {        
  13.         Total=Total+1
  14.  
  15.         document.getElementById("choice1A").disabled=true;
  16.  
  17.         if ((document.getElementById("choice1A").value==document.getElementById("text1").value) &&(document.getElementById("choice1A").checked)) correct=correct+1;
  18.  
  19.         document.getElementById("choice1B").disabled=true;
  20.  
  21.         if ((document.getElementById("choice1B").value==document.getElementById("text1").value) &&(document.getElementById("choice1B").checked)) correct=correct+1;
  22.  
  23.         document.getElementById("choice1C").disabled=true;
  24.  
  25.         if ((document.getElementById("choice1C").value==document.getElementById("text1").value) &&(document.getElementById("choice1C").checked)) correct=correct+1;
  26.  
  27.         document.getElementById("choice1D").disabled=true;
  28.  
  29.         if ((document.getElementById("choice1D").value==document.getElementById("text1").value) &&(document.getElementById("choice1D").checked)) correct=correct+1;
  30.  
  31.         if ((document.getElementById("choice1A").value==document.getElementById("text1").value)) document.getElementById("C1A").style.color='red';
  32.  
  33.         if ((document.getElementById("choice1B").value==document.getElementById("text1").value)) document.getElementById("C1B").style.color='red';
  34.  
  35.         if ((document.getElementById("choice1C").value==document.getElementById("text1").value)) document.getElementById("C1C").style.color='red';
  36.  
  37.         if ((document.getElementById("choice1D").value==document.getElementById("text1").value)) document.getElementById("C1D").style.color='red';
  38. }
  39.  
  40. oElement = document.getElementById("choice2A");
  41. if (oElement) {
  42.         Total=Total+1
  43.         document.getElementById("choice2A").disabled=true;
  44.  
  45.         if ((document.getElementById("choice2A").value==document.getElementById("text2").value) &&(document.getElementById("choice2A").checked)) correct=correct+1;
  46.  
  47.         document.getElementById("choice2B").disabled=true;
  48.  
  49.         if ((document.getElementById("choice2B").value==document.getElementById("text2").value) &&(document.getElementById("choice2B").checked)) correct=correct+1;
  50.  
  51.         document.getElementById("choice2C").disabled=true;
  52.  
  53.         if ((document.getElementById("choice2C").value==document.getElementById("text2").value) &&(document.getElementById("choice2C").checked)) correct=correct+1;
  54.  
  55.         document.getElementById("choice2D").disabled=true;
  56.  
  57.         if ((document.getElementById("choice2D").value==document.getElementById("text2").value) &&(document.getElementById("choice2D").checked)) correct=correct+1;
  58.  
  59.         if ((document.getElementById("choice2A").value==document.getElementById("text2").value)) document.getElementById("C2A").style.color='red';
  60.  
  61.         if ((document.getElementById("choice2B").value==document.getElementById("text2").value)) document.getElementById("C2B").style.color='red';
  62.  
  63.         if ((document.getElementById("choice2C").value==document.getElementById("text2").value)) document.getElementById("C2C").style.color='red';
  64.  
  65.         if ((document.getElementById("choice2D").value==document.getElementById("text2").value)) document.getElementById("C2D").style.color='red';
  66. }
  67.  
  68. document.getElementById("button1").disabled=true;
  69.  
  70. alert(" Tra loi dung " + correct + " cau trong tong so " + Total + " cau.");
  71. }
  72.  
  73.     </script>
Feb 16 '08 #1
Share this Question
Share on Google+
10 Replies


acoder
Expert Mod 15k+
P: 16,027
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Feb 18 '08 #2

acoder
Expert Mod 15k+
P: 16,027
I want to creat a post like this blog:
http://onlinetoefltest.blogspot.com/...-lesson-1.html

When you chose all the answers and click show answer a msg box will appear and tells how many answers are correct

I view the blog source and copied all the code to my post but it didn't work when i click the show answer button in my post.

Can any one help me with the code?
So what happens in your version? Do you get any errors?
Feb 18 '08 #3

P: 4
So what happens in your version? Do you get any errors?
The code is all correct but when i post a new blog in blogger, it doesn't work.
Feb 19 '08 #4

acoder
Expert Mod 15k+
P: 16,027
Can you post a link to your version.
Feb 19 '08 #5

P: 4
http://studyenglishchinese.blogspot.com/

I don't know why when i clicked the show answers button nothing happened although the code is right because i've tested the code of Evrsoft. How can it work in blogger, i don't know if blogger needs a special editor to edit it.

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. <script id="clientEventHandlersJS" language="javascript">
  2.  
  3. function button1_onclick() {
  4.  
  5. var correct,Total;
  6.  
  7. Total=0;
  8.  
  9. correct= 0;
  10.  
  11. oElement = document.getElementById("choice1A");
  12. if (oElement) {        
  13.         Total=Total+1
  14.  
  15.         document.getElementById("choice1A").disabled=true;
  16.  
  17.         if ((document.getElementById("choice1A").value==document.getElementById("text1").value) &&(document.getElementById("choice1A").checked)) correct=correct+1;
  18.  
  19.         document.getElementById("choice1B").disabled=true;
  20.  
  21.         if ((document.getElementById("choice1B").value==document.getElementById("text1").value) &&(document.getElementById("choice1B").checked)) correct=correct+1;
  22.  
  23.         document.getElementById("choice1C").disabled=true;
  24.  
  25.         if ((document.getElementById("choice1C").value==document.getElementById("text1").value) &&(document.getElementById("choice1C").checked)) correct=correct+1;
  26.  
  27.         document.getElementById("choice1D").disabled=true;
  28.  
  29.         if ((document.getElementById("choice1D").value==document.getElementById("text1").value) &&(document.getElementById("choice1D").checked)) correct=correct+1;
  30.  
  31.         if ((document.getElementById("choice1A").value==document.getElementById("text1").value)) document.getElementById("C1A").style.color='red';
  32.  
  33.         if ((document.getElementById("choice1B").value==document.getElementById("text1").value)) document.getElementById("C1B").style.color='red';
  34.  
  35.         if ((document.getElementById("choice1C").value==document.getElementById("text1").value)) document.getElementById("C1C").style.color='red';
  36.  
  37.         if ((document.getElementById("choice1D").value==document.getElementById("text1").value)) document.getElementById("C1D").style.color='red';
  38. }
  39. oElement = document.getElementById("choice2A");
  40. if (oElement) {
  41.         Total=Total+1
  42.         document.getElementById("choice2A").disabled=true;
  43.  
  44.         if ((document.getElementById("choice2A").value==document.getElementById("text2").value) &&(document.getElementById("choice2A").checked)) correct=correct+1;
  45.  
  46.         document.getElementById("choice2B").disabled=true;
  47.  
  48.         if ((document.getElementById("choice2B").value==document.getElementById("text2").value) &&(document.getElementById("choice2B").checked)) correct=correct+1;
  49.  
  50.         document.getElementById("choice2C").disabled=true;
  51.  
  52.         if ((document.getElementById("choice2C").value==document.getElementById("text2").value) &&(document.getElementById("choice2C").checked)) correct=correct+1;
  53.  
  54.         document.getElementById("choice2D").disabled=true;
  55.  
  56.         if ((document.getElementById("choice2D").value==document.getElementById("text2").value) &&(document.getElementById("choice2D").checked)) correct=correct+1;
  57.  
  58.         if ((document.getElementById("choice2A").value==document.getElementById("text2").value)) document.getElementById("C2A").style.color='red';
  59.  
  60.         if ((document.getElementById("choice2B").value==document.getElementById("text2").value)) document.getElementById("C2B").style.color='red';
  61.  
  62.         if ((document.getElementById("choice2C").value==document.getElementById("text2").value)) document.getElementById("C2C").style.color='red';
  63.  
  64.         if ((document.getElementById("choice2D").value==document.getElementById("text2").value)) document.getElementById("C2D").style.color='red';
  65. }
  66. document.getElementById("button1").disabled=true;
  67.  
  68. alert(" Tra loi dung " + correct + " cau trong tong so " + Total + " cau.");
  69. }
  70.  
  71.   </script>
  72.  
[HTML]1. Upon hatching, ________. <input id="text1" style="visibility: hidden; width: 1px;" value="A">
<input id="choice1A" value="A" name="choice1" type="radio"><label id="C1A">(A) young ducks know how to swim</label>
<input id="choice1B" value="B" name="choice1" type="radio"><label id="C1B">(B) swimming is known by young ducks</label>
<input id="choice1C" value="C" name="choice1" type="radio"><label id="C1C">(C) the knowledge of swimming is in young ducks</label>
<input id="choice1D" value="D" name="choice1" type="radio"><label id="C1D">(D) how to swim is known in young ducks</label>
2. Some of the rainwater from clouds evaporates before ________. <input id="text2" style="visibility: hidden; width: 1px;" value="A">
<input id="choice2A" value="A" name="choice2" type="radio"><label id="C2A">(A) reaching the ground</label>
<input id="choice2B" value="B" name="choice2" type="radio"><label id="C2B">(B) to reach the ground</label>
<input id="choice2C" value="C" name="choice2" type="radio"><label id="C2C">(C) reach the ground</label>
<input id="choice2D" value="D" name="choice2" type="radio"><label id="C2D">(D) the ground reaches</label>
<input language="javascript" id="button1" onclick="button1_onclick();" value="Show answer[/HTML]
Feb 20 '08 #6

P: 85
i havent seen much of your code but when i went to your test page, you seem to be missing an opening bracket after your function button1_onclick() in line 194
[HTML]<script id="clientEventHandlersJS" language="javascript">function button1_onclick() var correct,Total;.......[/HTML]

and in line 234 u have put a <br /> in js code after the function button1_onclick()
[HTML]script id="clientEventHandlersJS" language="javascript">function button1_onclick() <br />{var correct,Total;Total=0;........[/HTML]

and in line 274
[HTML]<script id="clientEventHandlersJS" language="javascript"><br />function button1_onclick() {<br />var correct,Total;<br />Total=0.........[/HTML]

and in line 150
[HTML]<script id="clientEventHandlersJS" type="text/javascript"><br /><br />function button1_onclick() {<br /><br />var correct,Total;<br /><br />Total=0;<br /><br />correct= 0..........[/HTML]

and all of these scripts have same id
Feb 20 '08 #7

100+
P: 141
Hi

some of the button1_onclick() has no' { ' try to place them
by finding the button1_onclick().

and in the script functions u should not use the <br /> directly u should use that by using document.write() like document.write("<br />");

try to remove the <br /> in all the scripts function then ur function will work.
since i have checked that i am making this comment .

it works fine if u remove <br/> and place it in document.write("<br />");

I want to creat a post like this blog:
http://onlinetoefltest.blogspot.com/...-lesson-1.html

When you chose all the answers and click show answer a msg box will appear and tells how many answers are correct

I view the blog source and copied all the code to my post but it didn't work when i click the show answer button in my post.

Can any one help me with the code?
Thanks in advance
Feb 20 '08 #8

100+
P: 141
Hi

some of the button1_onclick() has no' { ' try to place them
by finding the button1_onclick().

and in the script functions u should not use the <br /> directly u should use that by using document.write() like document.write("<br />");

try to remove the <br /> in all the scripts function then ur function will work.
since i have checked that i am making this comment .

it works fine if u remove <br/> and place it in document.write("<br />");




i havent seen much of your code but when i went to your test page, you seem to be missing an opening bracket after your function button1_onclick() in line 194
[HTML]<script id="clientEventHandlersJS" language="javascript">function button1_onclick() var correct,Total;.......[/HTML]

and in line 234 u have put a <br /> in js code after the function button1_onclick()
[HTML]script id="clientEventHandlersJS" language="javascript">function button1_onclick() <br />{var correct,Total;Total=0;........[/HTML]

and in line 274
[HTML]<script id="clientEventHandlersJS" language="javascript"><br />function button1_onclick() {<br />var correct,Total;<br />Total=0.........[/HTML]

and in line 150
[HTML]<script id="clientEventHandlersJS" type="text/javascript"><br /><br />function button1_onclick() {<br /><br />var correct,Total;<br /><br />Total=0;<br /><br />correct= 0..........[/HTML]

and all of these scripts have same id
Feb 20 '08 #9

P: 4
I replace all the <br/> with document.write("<br />") but it can't help. When i clicked on show answers it doesn't not work. I don't know why this blog can do
http://onlinetoefltest.blogspot.com/2007/08/toefl-lesson-1.html
I just copied the code from this blog and post in mine. Thank you very much Vee10. I really appreciated your help.
Feb 23 '08 #10

acoder
Expert Mod 15k+
P: 16,027
If you check the error console, you will see errors, e.g.
missing ; before statement
http://studyenglishchinese.blogspot.com/
Line 153
missing { before function body
http://studyenglishchinese.blogspot.com/
Line 197
Correct them (by adding ; and {).
Feb 25 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.