Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When a form is a questionaire......?

Status
Not open for further replies.

quantuman

Technical User
Jun 8, 2000
6
CA
I am creating a trivia website where only one radio button can be correct. I know how to write radio buttons, but how can you make it that when the form is submitted, the write answers come back.

Basically: how do you write a radio button so that one button is correct?
 
You must give the same name at all the radio button :

<input type=&quot;radio&quot; name=&quot;myradio&quot; value=&quot;button 1&quot;><br>
<input type=&quot;radio&quot; name=&quot;myradio&quot; value=&quot;button 2&quot;><br>
<input type=&quot;radio&quot; name=&quot;myradio&quot; value=&quot;button 3&quot;>

 
I'm not totally sure what you're asking. Are you saying that you want the information submitted in the form to include the correct answers as well as the user's answers?

If so, the better way to handle this is have the correct answers stored somewhere on the server side (i.e. in a database or in the CGI script that processes the form data itself). If you embed the answers in the HTML somewhere, it's quite easy for the user to cheat.

If, for whatever reason, you're stuck on an HTML solution, you can code a hidden field that corresponds to the correct answer to each question on the form:

<form action=&quot;myscript.cgi&quot; method=&quot;post&quot;>
<!-- Questions -->
<pre>
1. What is 1 + 1?

3 <input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;3&quot;>
2 <input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;2&quot;>
-33.5 <input type=&quot;radio&quot; name=&quot;q1&quot; value=&quot;33.5&quot;>

2. What is 1 - 1?

97 <input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;97&quot;>
4 <input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;4&quot;>
0 <input type=&quot;radio&quot; name=&quot;q2&quot; value=&quot;0&quot;>

<!-- Insert more questions here -->
</pre>
<!-- Answers -->
<input type=&quot;hidden&quot; name=&quot;q1Answer&quot; value=&quot;2&quot;>
<input type=&quot;hidden&quot; name=&quot;q2Answer&quot; value=&quot;0&quot;>
</form>

HTH,

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top