Forums

Assign numerical values to radio buttons in a quiz

jeggers 28 Dec, 2014
I am creating a quiz using radio buttons. There is only one correct answer to each question and I want to enter into the DB a 1 for the correct answer.

Question 1. If two pounds of candy cost $1.20, what would 1/2 pound cost at the same rate?
1=$.30
2=$.45
3=$.60
4=$.90
5=$2.40

$.30 is the correct answer which I want to enter a 1 for in the DB, with 0's for the rest. How can I do this?
GreyHead 29 Dec, 2014
Hi jeggers,

It depends on your students. The simplest solution is to use
1=$.30
0=$.45
0=$.60
0=$.90
0=$2.40
but bright students can peek and see the correct answer. Otherwise you have to look up the answer after the from is submitted. Then the options might be
a1=$.30
a2=$.45
a3=$.60
a4=$.90
a5=$2.40
Then you can look up using Custom Code, if this q1:
<?php
if ( $form->data['q1'] == 'a1' ) {
  $form->data['q1'] = 1;
} else {
  $form->data['q1'] = 0;
}
?>

Bob
This topic is locked and no more replies can be posted.