Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:35:28+00:00 2026-06-17T12:35:28+00:00

I am using PHP MYSQL to generate a small multi page quiz. I am

  • 0

I am using PHP MYSQL to generate a small multi page quiz. I am able to display the questions and the multiple choice answers as radio button choices(thanks to help from Stackoverflow). The problem I am running into is – is there a way to trigger an action as soon as a user clicks on a radio button? If the user has selected a wrong answer, I want to give immediate feedback and say the answer is wrong and why it is wrong. If the user has selected a correct answer, I want to display correct answer.

I have looked at $_GET,$_POST and $_REQUEST but all require the answers to be “Submit”ted for the process to begin in PHP. I want the action to begin (using PHP source code) as soon as the user clicks a radio button.

Note: I have looked at several questions here that seem to utilize jQuery for the above. Is it possible to do without jQuery or Javascript?

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:35:29+00:00Added an answer on June 17, 2026 at 12:35 pm

    Yes it is possible and to use jQuery is the best solution.

    http://api.jquery.com/jQuery.ajax/

    <?PHP
    if (!empty($_GET['action']) && $_GET['action'] == 'ajax_check') {
      // I a final solution you should load here the answer of the question from database by name
      $answers = array(
        'foo' => 1,
        'baa' => 3,
      );    
    
      // Prepare and default answer in error case
      $return = array(
        'message' => 'Invalud choise',
      );
    
      if (isset($answers[$_GET['name']])) {
        // If question/answer was found in database, check if users chouse is correct
        if ($answers[$_GET['name']] == $_GET['value']) {
          $return['message'] = 'Correct answer'; 
        } else {
          $return['message'] = 'Wrong answer'; 
        }
      }
    
      // Return answer to java script
      header('Content-type: text/json');
      echo json_encode($return);
      die();
    }
    ?>
    
    Question 1
    <input type="radio" name="foo" value="1" class="question_radio" />
    <input type="radio" name="foo" value="2" class="question_radio" />
    <input type="radio" name="foo" value="3" class="question_radio" />
    <input type="radio" name="foo" value="4" class="question_radio" />
    <br />
    
    Question 2
    <input type="radio" name="baa" value="1" class="question_radio" />
    <input type="radio" name="baa" value="2" class="question_radio" />
    <input type="radio" name="baa" value="3" class="question_radio" />
    <input type="radio" name="baa" value="4" class="question_radio" />
    
    <!-- Load jquery framework from google, dont need to host it by your self -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function () { 
        // When document was loadet succesfull
    
        $(".question_radio").click(function () {
          // Listen on all click events of all objects with class="question_radio"
          // It is also possible to listen and input[type=radio] but this can produce false possitives.
    
          // Start communication to PHP
          $.ajax({
            url: "test.php", // Name of PHP script
            type: "GET",
            dataType: "json",  // Enconding of return values ²see json_encode()
            data: { // Payload of request
              action: 'ajax_check', // Tel PHP what action we like to process
              name: $(this).attr('name'),
              value: $(this).val(), 
            }
          }).done(function(data) {
            // Procces the answer from PHP
            alert( data.message );
          });
        });
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using TCPDF to convert a page generated by php from a mysql
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
If i generate HTML data from MySQL using PHP like this: /* SQL query
Using php and mysql (and Drupal), I want to generate an index based on
How can I generate graphs and charts from a mysql database using php? I'm
I am using an ExtJS 3.0 grid and generate data from PHP using MySQL.
I am trying to generate a grouped/stratified report using PHP and MySQL. tbl_items has
I'm trying to generate a mysql dump file from PHP using the following: exec('mysqldump
i am using php,mysql,jquery. My case is that step 1 : i generate 10
I'm using php to generate an html page that displays blog/thread items, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.