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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button question???? help

Status
Not open for further replies.

cs7536

Programmer
Apr 20, 2003
130
US
I have created a quiz using mysql, php on windows2000..

Now I created an application that we will use to input the wuestions from the admin into the DB.
The issue comes here!!!!!

When I display the questions on a page the radio buttons which are on a:

a. o Woman
b. o The ape
c. o The ground
d. o None of the above

When I display a list of questions, it is treating all the radio buttons on the other questions a one long question..

example:
question 1 and question 2
a-d display on both which is cool.. but when you answer question 1, and then try to answer question2 it removes the selected radio and puts it on question 2 instead of leaving question 1, and treatinf the radiobuttons on question 2 seperate.

Hope I made my self clear enoug for some help..

Thanks
Max

Nothing is hard when you realy want to learn it.

Max
 
You need to give the radio buttons distinct names - per question.
So, let's say R1 should be:
Code:
<input type=&quot;radio&quot; name=&quot;question1&quot; value=&quot;answerA&quot;>
<input type=&quot;radio&quot; name=&quot;question1&quot; value=&quot;answerB&quot;>
... etc ...
<input type=&quot;radio&quot; name=&quot;question2&quot; value=&quot;answerA&quot;>
<input type=&quot;radio&quot; name=&quot;question2&quot; value=&quot;answerB&quot;>

This is a HTML question, but since you used PHP to create the button it's fine. You will also need PHP to generate and keep track of the questions and the dynamically generated radio button name.
 
I created a radioB but they are names q1 so that they will make only one selection depending on the choosen answer.. I guest my issue is coming in where every question is pulling the same radioB's so no matter what question you answer it replaces tje last question, Yes it is true that each question should have a diff name for the radioB's but what IO have done is created one set of radioB's and every question pulls the radioB code and inserts it on each question. How can I create a different name for each radioB per question with out writing repeted code..

See the a,b,c,d options are stored in the DB, as well as the correct answer that it will compare to the users answers. When it displays, it displays all correct but like you said it is treating the radios as if they were one radioB name.

Nothing is hard when you realy want to learn it.

Max
 
every question pulls the radioB code and inserts it on each question

Just edit you radioB code into a function that accepts a parameter for the radioB name. Call it each time when you need the radioBs displayed - this means the repetition of 1 line, namely the function call.
Code:
function makeRadio($questionID){
   echo('<input type=&quot;radio&quot; name=&quot;'.$questionID.'&quot; value=&quot;choiceA&quot;>ChoiceA<br>');
   echo('<input type=&quot;radio&quot; name=&quot;'.$questionID.'&quot; value=&quot;choiceB&quot;>ChoiceB<br>');
# etc.
}
# when looping through the questions or printing a question pass the unique ID:
echo(&quot;Question: .....&quot;);
makeRadio('question1');
 
Thanks I will try that..

Once again thank you.
max

Nothing is hard when you realy want to learn it.

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top