Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newbie: Javascript help for PHP project

    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.

  • #2
    New Coder
    Join Date
    Jun 2009
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Do you have some code written up?

    Regards,
    Pembar

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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>
    Last edited by apcalculus; 06-26-2009 at 06:23 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •