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

  • Home
  • SEARCH
  • 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 6623663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:33:33+00:00 2026-05-25T21:33:33+00:00

I’m making a quiz with PHP, but I am using JavaScript to go between

  • 0

I’m making a quiz with PHP, but I am using JavaScript to go between the questions first and then I submit the form and let PHP do the rest.

I made two JavaScript functions called ChangeQuestion() and BackQuestion().

function ChangeQuestion(prev, next) {
    $('#' + prev).fadeOut(600, function() {
        $('#' + next).fadeIn(600);
    });
}

function BackQuestion(last, prev) {
    $('#' + prev).fadeOut(600, function() {
        $('#' + last).fadeIn(600);
    });
}

They’re pretty basic. But what I would like to do is check if their is at least one radio button checked in a question before continuing with the function. You’ll be able to see in my markup/HTML how I’m using the above functions.

First of all, here’s a jsFiddle: http://jsfiddle.net/3XdUA/

Here’s my markup:

<form id="quiz1" name="quiz1" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    <div id="starter">
        Hello! Welcome to the HTML Quiz powered by PHP. Click on Start to begin.
        <br /><br />
        <button type="button" onclick="ChangeQuestion('starter','question1');$('#qIndicator').fadeIn(800);">Start &raquo;</button>
    </div>
    <div id="question1" style="display:none;">
        1. What does HTML stand for?
        <br />
        <br />
        <input type="radio" name="q1" id="q1-a1" /> 
        <label for="q1-a1">Hyperlinks and Text Markup Language</label>
        <br />
        <input type="radio" name="q1" id="q1-a2" /> 
        <label for="q1-a2">Home Text Markup Language</label>
        <br />
        <input type="radio" name="q1" id="q1-a3" /> 
        <label for="q1-a3">Hyper Text Markup Language</label>
        <br />
        <input type="radio" name="q1" id="q1-a4" /> 
        <label for="q1-a4">Hyper Text Marking Language</label>
        <br /><br />
        <button type="button" onclick="ChangeQuestion('question1','question2');$('#qIndicator').html('Question 2 of 10');">Next &raquo;</button>
    </div>

    <div id="question2" style="display:none;">
        2. What is the proper way to add a blue background to the <code>&lt;body></code> and remove the margin &amp; padding?
        <br />
        <br />
        <input type="radio" name="q2" id="q2-a1" /> 
        <label for="q2-a1">&lt;body backgroundColor="blue" padding="0" margin="0"&gt;</label>
        <br />
        <input type="radio" name="q2" id="q2-a2" /> 
        <label for="q2-a2">&lt;body style="background-color: blue; margin: 0; padding: 0;"&gt;</label>
        <br />
        <input type="radio" name="q2" id="q2-a3" /> 
        <label for="q2-a3">&lt;body style="backgroundColor: blue; margin: 0px; padding: 0px;"&gt;</label>
        <br />
        <input type="radio" name="q2" id="q2-a4" /> 
        <label for="q2-a4">&lt;body background="blue" padding="0" margins="0"&gt;</label>
        <br /><br />
        <button type="button" onclick="BackQuestion('question1','question2');$('#qIndicator').html('Question 1 of 10');">&laquo; Back</button>
        <button type="button" onclick="ChangeQuestion('question2','question3');$('#qIndicator').html('Question 3 of 10');">Next &raquo;</button>
    </div>

    <div id="question3" style="display:none;">
        3. Which of the following font styling tags isn&#39;t valid?
        <br />
        <br />
        <input type="radio" name="q3" id="q3-a1" /> 
        <label for="q3-a1">&lt;small&gt;</label>
        <br />
        <input type="radio" name="q3" id="q3-a2" /> 
        <label for="q3-a2">&lt;strong&gt;</label>
        <br />
        <input type="radio" name="q3" id="q3-a3" /> 
        <label for="q3-a3">&lt;em&gt;</label>
        <br />
        <input type="radio" name="q3" id="q3-a4" /> 
        <label for="q3-a4">&lt;large&gt;</label>
        <br /><br />
        <button type="button" onclick="BackQuestion('question2','question3');$('#qIndicator').html('Question 2 of 10');">&laquo; Back</button>
        <button type="button" onclick="ChangeQuestion('question3','question4');$('#qIndicator').html('Question 4 of 10');">Next &raquo;</button>
    </div>

    <div id="question4" style="display:none;">
        4. Suppose you have this HTML on your page:
        <br /><br />
        <code>
            &lt;a name="target4"&gt;Old listing&lt;/a&gt;
        </code>
        <br /><br />
        How would you link to the above target?
            <br />
            <br />
            <input type="radio" name="q4" id="q4-a1" /> 
            <label for="q1-a1">&lt;a url="#target4"&gt;Check Old Listing as well&lt;/a&gt; </label>
            <br />
            <input type="radio" name="q4" id="q4-a2" /> 
            <label for="q1-a2">&lt;a href="#target4"&gt;Check Old Listing as well&lt;/a&gt;</label>
            <br />
            <input type="radio" name="q4" id="q4-a3" /> 
            <label for="q1-a3">&lt;link url="target4"&gt;Check Old Listing as well&lt;/link&gt; </label>
            <br />
            <input type="radio" name="q4" id="q4-a4" /> 
            <label for="q1-a4">&lt;a href="Listing.target4"&gt;Check Old Listing as well&lt;/a&gt;</label>
            <br /><br />
            <button type="button" onclick="BackQuestion('question3','question4');$('#qIndicator').html('Question 3 of 10');">&laquo; Back</button>
            <button type="button" onclick="ChangeQuestion('question4','question5');$('#qIndicator').html('Question 5 of 10');">Next &raquo;</button>
        </div>

            <div id="question5" style="display:none;">
                5. What does HTML stand for?
                <br />
                <br />
                <input type="radio" name="q2" id="q2-a1" /> 
                <label for="q1-a1">Hyper Tool Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a2" /> 
                <label for="q1-a2">Home Text Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a3" /> 
                <label for="q1-a3">Hyper Text Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a4" /> 
                <label for="q1-a4">Hyper Text Marking Language</label>
                <br /><br />
                <button type="button" onclick="BackQuestion('question4','question5');$('#qIndicator').html('Question 4 of 10');">&laquo; Back</button>
                <button type="button" onclick="ChangeQuestion('question5','question6');$('#qIndicator').html('Question 6 of 10');">Next &raquo;</button>
            </div>

            <div id="question6" style="display:none;">
                6. What does HTML stand for?
                <br />
                <br />
                <input type="radio" name="q2" id="q2-a1" /> 
                <label for="q1-a1">Hyper Tool Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a2" /> 
                <label for="q1-a2">Home Text Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a3" /> 
                <label for="q1-a3">Hyper Text Markup Language</label>
                <br />
                <input type="radio" name="q2" id="q2-a4" /> 
                <label for="q1-a4">Hyper Text Marking Language</label>
                <br /><br />
                <button type="button" onclick="BackQuestion('question5','question6');$('#qIndicator').html('Question 5 of 10');">&laquo; Back</button>
                <button type="button" onclick="ChangeQuestion('question6','question7');$('#qIndicator').html('Question 7 of 10');">Next &raquo;</button>
            </div>

        </form>

Yes, it is long. Sorry about that. But, I provided a jsFiddle which would be much easier to understand. (because of the preview, etc.)

I do know how to check if a radio is selected, but I do not know how to make sure that one is selected with this function.

  • 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-05-25T21:33:34+00:00Added an answer on May 25, 2026 at 9:33 pm

    Use the :checked pseudo selector.

    function ChangeQuestion(prev, next) {
        var prevQ = $('#'+prev);
        var numChecked = prevQ.find('input[type=radio]:checked').length;
    
        if( prev !=='starter' && numChecked == 0 ) {
            // no radio checked in this question
            return;
        }
    
        prevQ.fadeOut(600, function() {
            $('#' + next).fadeIn(600);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.