Article:
 |
|
PHP Form Handling
|
| Subject: |
|
Display selected value in radio buttons when previous button is clicked |
| Date: |
|
2008-04-24 12:30:38 |
| From: |
|
radice
|
|
|
|
Hello
I have created some evaluation pages. It is one page when i am keeping track of question and displaying the question when next and previous is clicked. I have a problem of displaying the previously selected values in the radio buttons when going back and forward. Here is the code i used.
function displayQuestionOne() {
$answer = $_SESSION['answerArray'][0];
echo "Answer".$answer;
$choice1 = $choice2 = $choice3 = $choice4 = '';
if ($answer == "Opens") $choice1='checked';
if ($answer == "Opened") $choice2='checked';
if ($answer == "Open") $choice3='checked';
if ($answer == "will opened") $choice4='checked';
?>
<tr>
<td colspan="3">
Select the correct answer </td>
<td width="13%"> </td>
</tr>
<tr>
<td width="7%">1.</td>
<td colspan="2">Sample Question 1</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<input type="radio" name="Question" value="Opens" <? $choice1 ?> /> Opens
<input type="radio" name="Question" value="Opened" /> Opened
<input type="radio" name="Question" value="Open" /> Open
<input type="radio" name="Question" value="will opened" /> will opened
</td>
<td> </td>
</tr>
<?
}
?>
Any help is appreciated.
Thanks
Radice
|
Showing messages 1 through 1 of 1.
-
Display selected value in radio buttons when previous button is clicked
2008-04-24 12:34:16
radice
[View]
// This displays Question 0
function displayQuestionOne() {
$answer = $_SESSION['answerArray'][0];
echo "Answer".$answer;
$choice1 = $choice2 = $choice3 = $choice4 = '';
if ($answer == "Opens") $choice1='checked';
if ($answer == "Opened") $choice2='checked';
if ($answer == "Open") $choice3='checked';
if ($answer == "will opened") $choice4='checked';
echo "Choice 1".$choice1."
";
echo "Choice 2".$choice2."
";
echo "Choice 3".$choice3."
";
echo "Choice 4".$choice4."
";
?>
<tr>
<td colspan="3">
Select the correct answer
</td><td width="13%"> </td>
</tr>
<tr>
<td width="7%">1.</td>
<td colspan="2">Maria, ____________the door please. It’s too hot in here.</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">
</td><input type="radio" name="Question" value="Opens" <? $choice1 ?> /> Opens
<input type="radio" name="Question" value="Opened" <? $choice2 ?>/> Opened
<input type="radio" name="Question" value="Open" <? $choice3 ?>/> Open
<input type="radio" name="Question" value="will opened" <? $choice4 ?>/> will opened
<td> </td>
</tr>
<?
}
?>