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

Making text appear with javascript.

P: 2
Hey everyone,

I am making an online quiz (school project) and basically I have 4 radio buttons (the options; multiple choice) and then an answer button. What I want is for the user to answer and submit it and then have javascript check the answer. I then want it to display an appropriate "correct" or "incorrect" below. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. <html xmlns='http://www.w3.org/1999/xhtml'>
  2. <head>
  3. <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
  4. <title>Networking Quiz :: #1</title>
  5. <link href='core-style.css' rel='stylesheet' type='text/css' />
  6. <link href='sub_style.css' rel='stylesheet' type='text/css' />
  7.  
  8. <script type='text/javascript'>
  9. function check() {
  10.   if(document.form1.term.value=='Answer'){
  11.     document.getElementById('correct').style.display='block';
  12.   }else{
  13.     document.getElementById('incorrect').style.display='block';
  14.   }
  15. }
  16. </script>
  17. </head>
  18.  
  19. <body>
  20. <center>
  21. <div id='content'>
  22. <div id='body'>
  23. <div id='question'>
  24. 1/39
  25. </div>
  26. <hr width='90%'>
  27. <div class='body_head'>
  28. Definition
  29. </div>
  30. <div class='main_text'>
  31. Used to connect to an ethernet network.
  32.   </div>
  33. <div class='body_head'>
  34. Terms
  35. </div>
  36. <div class='review_text'>
  37. <form name='form1' id='terms' method='get' action=''>
  38. <input type='radio' name='term' value='Answer'>Network Interface Card (NIC)<br />
  39. <input type='radio' name='term' value='2'>Bluetooth<br />
  40. <input type='radio' name='term' value='3'>Voice Over Internet Protocol (VoIP)<br />
  41. <input type='radio' name='term' value='4'>Internet
  42. <p><input type='button' value='Answer!' name='answer' onclick='check();'></p>
  43. </form>
  44. </div>
  45. </div>
  46. <hr width='90%'>
  47. <div id='correct' style="display:none;">
  48. <div id='answer'>
  49. Correct  Correct
  50. </div>
  51. <div id='button'>
  52. <a href='switch.php'>Next</a>
  53. </div>
  54. </div>
  55.  
  56. <div id='incorrect' style="display:none;">
  57. <div id='answer'>
  58. Incorrect!!!! Incorrect!!!!!
  59. </div>
  60. <div id='button'>
  61. <a href='switch.php'>Next</a>
  62. </div>
  63. </div>
  64. </div>
  65. </center>
  66. </body>
  67. </html>
  68.  
All this does is come up with "incorrect" every time no matter what option is selected (check it out at www.cwilliams.ca/networking/nic.php). Any help would be GREATLY appreciated.
Jan 24 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Use the checked property to determine which radio button has been selected.

Just a note: ids should be unique within a page. You have some duplicate IDs.
Jan 24 '08 #2

P: 2
Thanks a ton!! That worked beautifully!
Jan 25 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Post again if you have any more questions.
Jan 25 '08 #4

Post your reply

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