473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Making text appear with javascript.

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
3 1956
acoder
16,027 Expert Mod 8TB
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
Thanks a ton!! That worked beautifully!
Jan 25 '08 #3
acoder
16,027 Expert Mod 8TB
You're welcome. Post again if you have any more questions.
Jan 25 '08 #4

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

Similar topics

10
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval...
4
by: MT | last post by:
Hi all, this sounds like an easy enough thing to do, but after spending 45 minutes searching google and various javascript sites I can't find out how to make a textfield (textbox or whatever you...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
2
by: tarmstrong | last post by:
Hi. I would like to create a link next to a caption, and when user clicks it, a new text appears and becomes . And when users clicks , it becomes and the text dissapears. I don't...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
1
by: bigmaddaz | last post by:
Ok im designing an application for working out compount interest. The user starts the page, 3 prompts appear, one asking for money invested, next asking for rate of interest, and last one asking for...
0
by: Dan | last post by:
Issue making textbox visible based on specific input from a radio button list in an EditItemTemplate I want to setup a gridview that when in edit mode and when the user selects "Other" from a...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.