...

View Full Version : Newbie: Javascript help for PHP project



apcalculus
06-23-2009, 09:31 PM
Hi all,

My knowledge of Javascript is minimal so I 'd appreciate any help with the following problem.

I am writing a multiple choice test in php. Most of the work is done except for the interactive piece, where the user selects a choice from ABCD and gets some feedback in return.

Each time my php program page loads it prints out the question, and a list of choices. Additionally, I can make it retrieve a value from a column on my database that represents the correct answer.

What I am having trouble with is writing a javascript so that when the user clicks one of the following

A
B
C
D

... the program checks against the php variable value, then returns an answer like "Correct" or "Try Again". I would appreciate some guidance with this, including the translation of the php variable into a javascript variable.

Thanks in advance.

Pembar
06-23-2009, 09:33 PM
Do you have some code written up?

Regards,
Pembar

apcalculus
06-25-2009, 08:51 PM
Thank you for following up. I don't have any javascript written yet, but here is the page where I want to add javascript, and I describe the tasks in the commented portion. I'd appreciate some help.


<table>
<tr valign=top>
<th width="150" scope="col"><div align="center"><font size="2"><strong>A.</strong></font></div></th>
<!--
Tasks:
1. Store php variable 'correctanswer' into javascript variable.
2. Write a function called 'checker' that checks the selected value.
3. The above functions will be called every time the user presses a button. So the text choice below can be converted to buttons or simply active links.
4. The feedback should be an alert type.

-->
<!-- print content for choice a -->
<th width="336" scope="col"> <?php echo $sel_page['choicea'];?>" alt="" border=0 align=left> </th>
</tr>
<tr>
<td valign="top"><div align="center"><font size="2"><strong>B.</strong></font> <strong></strong></strong></div></td>

<!-- print content for choice b -->
<td valign="top"> <?php echo $sel_page['choiceb'];?> </td>
</tr>
<tr>
<td valign="top"><div align="center"><font size="2"><strong>C.</strong></font> <strong></strong></strong></div></td>

<!-- print content for choice c -->
<td valign="top"> <?php echo $sel_page['choicec'];?> </td>
</tr>
<tr>
<td valign="top"><div align="center"><font size="2"><strong>D.</strong></font> <strong></strong></strong></div></td>

<!-- print content for choice d -->
<td valign="top"> <?php echo $sel_page['choiced'];?> </td>
</tr>
<tr>
<td valign="top"><div align="center"><font size="2"><strong>E.</strong></font> <strong></strong></strong></div></td>

<!-- print content for choice e -->
<td valign="top"> <?php echo $sel_page['choicee'];?> </td>
</tr>
</table>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum