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 775415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:17:06+00:00 2026-05-14T19:17:06+00:00

Ok before i make spaghetti of this code i thought id ask around here.

  • 0

Ok before i make spaghetti of this code i thought id ask around here. ive made a quiz for an online site.

The answers are stored in an array, and ive a function that checks the answers array to what youve clicked. then it counts them and gives you your score.

but i want to change the clor of the right answer wen the user clicks the score button. so the correct answers are highlighted. something like this https://www.shutterpoint.com/Home-Quiz.cfm (just hit submit at the bottom, no need to do the quiz).

the little answer icon at the side looks flashy but id rather just have the text change color. heres how my questions are formatted

<p>Film speed refers to:</p>
<p id = "question1">
<input type="radio" name="question1" id="Wrong" value = "a" onClick = "recordAnswer(1,this.value)"/>How long it takes to develop film. <br/>
<input type="radio" name="question1" id="Wrong" value = "b" onClick = "recordAnswer(1,this.value)"/>How fast film moves through film-transport system.  <br/>
<input type="radio" name="question1" id="Answer" value = "c" onClick = "recordAnswer(1,this.value)"/>   How sensitive the film is to light.  <br/>
<input type="radio" name="question1" id="Wrong" value = "d" onClick = "recordAnswer(1,this.value)"/>    None of these makes sense. <br/></p>

and these are the two functions that are called throughout. record answer is called every time the user clicks a button

 function recordAnswer(question,answer)
{
answers[question-1] = answer;
}

this is the final button which calculates the score

function scoreQuiz()
{
var totalCorrect = 0;
for(var count = 0; count<correctAnswers.length;count++)
{
    if(answers[count]== correctAnswers[count])

    totalCorrect++;

}
<!--
alert("You scored " + totalCorrect + " out of 12 correct!");
-->
}

another function is best i think. ive already made attempts at it and know i have to set the color using

document.getElementById('Answer').style.color = '#0000ff';

onyl problem is ‘Answer’ doesnt seem to be registering. anyone shed some light?


ok so i cant have two or more of the same ids.

what about

if(value == correctAnswers[])
{
// change the color.
}
  • 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-14T19:17:07+00:00Added an answer on May 14, 2026 at 7:17 pm

    QUICK RESPONCE:

    USE <P>

        <p>
        <input type="radio" name="question_1" class="wrong" value="a" />
        How long it takes to develop film. 
      </p>
    

    THEN

    if(value == correctAnswers[])
    {
    YOUR_ELEMENT.parentNode.style.color = 'green';
    }
    

    IMPROVEMENT

    DEMO: http://jsbin.com/aceze/26

    hi Overtone!

    first of all you need to restyle a litte your HTML schema!

    you have multiple id="Wrong" instead of class="Wrong"

    then here how your code should look:

    var answers = { 1:'a' , 2:'f' , 3:'h' };
    
        function checkQuestions() {
        var form_elements = document.question_form.elements.length;
    
        for ( var i = 0; i < form_elements; i++ )
        {
            var type = question_form.elements[i].type;
            if ( type == "radio" ){
            var quest = question_form.elements[i];
            //if ( quest.checked ) {
            var question_index = parseInt(quest.name.split('_')[1]);
            //}
            if ( quest.value == answers[question_index] ) {
            quest.parentNode.style.border = '1px solid green';
            quest.parentNode.style.color = 'green';
              } else {
            //quest.parentNode.style.border = '1px solid red';
            quest.parentNode.style.color = 'red';
              }
          }
        }
      }
    

    USE a FORM and one time SUBMIT BUTTON instead of adding onclick to each RADIO like this

     <form name="question_form" id="question_form" method="POST" action='#'>
          <div id="question_1"> <H4>QUESTIONS TIME 1</H4>
          </div>
          <p>
            <input type="radio" name="question_1" class="wrong" value="a" />
            How long it takes to develop film.
          </p>
          <p>
            <input type="radio" name="question_1" class="wrong" value="b" />
            How fast film moves through film-transport system.
          </p>
          <p>
            <input type="radio" name="question_1" class="answer" value="c" />
            How sensitive the film is to light.
          </p>
          <p>
            <input type="radio" name="question_1" class="wrong" value="d" />
            None of these makes sense. 
          </p>
    
           ...
           ...
    
            <input type="radio" name="question_2" class="wrong" value="h" />
            <span>None of these makes sense. 
            </span>
          </p>
    
          <input type="submit" name="submit" onclick="checkQuestions();return false;" value="submit"/>
        </form> 
    

    PS: demo example updated with style… for sake!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

before posting the whole code, i wanted to make sure I am not missing
Before I get into the details of this problem, I'd like to make the
Before I do this I figured I would ask if it was the best
I often make a collection field unmodifiable before returning it from a getter method:
Something i've never really done before, but what is the best way to make
I would like to produce an executable that could make an update verification before
Before you answer this I have never developed anything popular enough to attain high
Before I start, I know there is this post and it doesn't answer my
Before I jump headlong into C#... I've always felt that C, or maybe C++,
Before, I have found the Cost in the execution plan to be a good

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.