473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making text appear with javascript.

2 New Member
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.c a/networking/nic.php). Any help would be GREATLY appreciated.
Jan 24 '08 #1
3 1979
acoder
16,027 Recognized Expert Moderator MVP
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
computerkid101
2 New Member
Thanks a ton!! That worked beautifully!
Jan 25 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
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
7760
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 (function(){this==window}, 100) I see true, the sad fact that 'this' is window and not an anim. What are some proper ways ? I would like to avoid
4
22740
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 want to call it) in an html form be a mandatory field. I'm guessing it would be on the "submit" click, and a pop-up would appear saying to enter...
1
2933
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 javascript; I just don't get the syntax at all. If anyone could help, I would appreciate it. I'm probably pretty close. Please note that because it's an...
2
1251
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 remember which JavaScript property I must work with. Thank you very much.
2
1450
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, AppendChild, making width grow? Hi,
1
1810
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 length of time money invested. All what now displays on the page is simple a calculate button. When the user clicks this calculate button, a new...
0
3656
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 radiolist that a text box will appear and the user can input text. I can get the textbox to appear after selecting other in the radiolist; however,...
1
4185
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 aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? ...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.