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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:51:32+00:00 2026-06-18T10:51:32+00:00

I’m working on an HTML5 quiz, where I’m using radio buttons for yes or

  • 0

I’m working on an HTML5 quiz, where I’m using radio buttons for yes or no questions, and then assigning each radio button a value of 0 or 1, then store the numerical value as a variable, then add all the variables together to score the quiz.

UPDATE!!!

Hey! I made the changes you suggested, but when I call the variable, it still comes up as undefined:

Here is my html:

<form class="answer" id="question_one">
  <input type="radio" class="styled" name="first_answer" value="1"/><!-- POSITIVE ANSWER -->
  <div class="answer_text">Yes</div>
  <input type="radio" class="styled" name="first_answer" value="0" /><!-- NEGATIVE ANSWER -->
  <div class="answer_text">No</div>
</form>

Here is my JavaScript:

$('#question_one input:radio[name=first_answer]').on('change', function () {
var first_question = parseInt(
    $("input[name=first_answer]:checked").val()
    );

});
I tried to include a bit more specificity to the jQuery object by only targeting Radio Buttons with name=first_asnwer. Maybe I screwed up?


  • 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-18T10:51:33+00:00Added an answer on June 18, 2026 at 10:51 am

    I think your issue here is the understanding of the $(document).ready() function. This function is executed once all the dependencies of the page have been loaded – CSS, JavaScript, etc…

    You have set your variables as soon as this function is executed which is probably before you even click on your first radio button! The solution here would be to only calculate the values after the user has finished answering. Possibly on a change event of the radio element –

    $(document).ready(function () {
      $('input:radio').on('change',function(){
        var $first_question = parseInt($("input[name=first_answer]:checked").val());
        var $second_question = parseInt($("input[name=second_answer]:checked").val());
        $first_question = $first_question? $first_question : 0; 
        $second_question = $second_question? $second_question : 0;
        var $total_score = $first_question + $second_question;
        alert($total_score);
      });
    });
    

    Here is a simple demo

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

Sidebar

Related Questions

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 am using JSon response to parse title,date content and thumbnail images and place
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this

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.